Search phillips site. They have an IC for compass, i believe that the part number is KMZ51 . But itsn't easy to build one, you need tho interface the Ic with a µC, just buy one already assembled for use. See at **broken link removed**.
And they have many others modules for robotics.
Compass schematics seem hard to find. Elektor have a simple project for a Lego RCX in the May 2002 issue - I've attached it here. It uses a Pewatron type 6945 compass sensor.
You may find more information in the manufactures datasheets here:
I have been searching for information about this aslo. My result is that the sensor to use is the KMZ51 from philips (got 3 of them already) There are also simular sensors and a lot of theoretical info from Honywell but they are much more expensive and harder to buy.
As I understand there are two ways of bulding a compas, the simpel way with two sensor and always keep the unit in upright position, the oter variant is using 3 magnetics sensors and do a tilt compensation with a two axis gyro of some sort. The last solution would be rather complicated, and where to get gyros thet dont cost 100s of $?
Some links with information i found after much searching...
Use a circular fluxgate or two (may be three) orthogonal straight fluxgates.
You will get 2D/3D vectors for the magnetic field.
Search internet for fluxgate compasses. Fluxgate sensors can be home brewed.
I remember Practical Electronics had one design of home made Fluxgate compass in '70 or '80s.