Magnetometers are key aiding sensors with accelerometers and are widely available, for instance in compasses and smartphones. Calibration is essential for magnetometers before use. However, most existing calibration methods rely on the geomagnetic field reference, which is easily disturbed by indoor ferromagnetic surroundings, such as the iron table and cabinet. Therefore, we proposed a new method that exploits a known differential magnetic field reference generated by a solenoid coil. The calibration algorithm with the new reference is proposed based on the strength of the differential magnetic field. Moreover, the alignment between the magnetometer and accelerometer is calibrated based on the orientation of the coil magnetic field. The algorithm is shown to have approximately equivalent performance compared with traditional methods that must be done with an undisturbed geomagnetic field. Besides, the alignment error between the magnetometer and accelerometer decreased from −0.03 ± 0.18 to −0.02 ± 0.05 after calibration.