Hi 史 大史,
You can have a look at the NXP Sensor Fusion, we provide a full and open source project for electronic compass.
As the application is embedded in a car, you can NOT run the full 3D compass because you have 2 axis only.
The Sensor Fusion provides different algorithms for electronic compasses and IMUs. In your case, you can use the 2D Automotive Compass which needs a 2D calibration: instead of drawing a 8 it takes only a circle as you mentioned.

Code samples are available on our website.
You have to check the
void fRun_3DOF_B_BASIC(struct SV_3DOF_B_BASIC *pthisSV, struct MagSensor *pthisMag, int32 loopcounter, int16 ithisCoordSystem)
function in the fusion.c file.
Anthony