Yes, having already been answerred, do note that using magnetometer as a compass is a fairly complicated task.
If you need more accuracy than, say, +/- 45 degrees, you need at minimum:
1) A calibration jig
2) A calibration and data compensation algorithm against hard iron and soft iron distortion. This needs to be unit-by-unit. The math for simple compensation (say, to +/- 20 degree accuracy) is fairly simple, do some offset & gain scaling, but for really usable compass, especially 3D (one which can be used at any angle), the math is very convoluted and I haven't been able to find any open-source implementation or freely available description
Getting low-noise data practically requires averaging over a long time, say second-scale. If you then need quick response, you need to do some sensor fusion with gyros, which in itself is fairly trivial if you have already solved 1 and 2.
PCB layout and device casing matters as well.
All of this is because the earth's magnetic field is very weak, interference sources are often much stronger, and all the nearby components and metallic materials distort the fields.
This is something I tried to do as a part of a bigger project, and never had time to do properly. It was more difficult than I thought.