Correct magnetometer placement app note from Kionix. Link here (PDF)
Electronic devices contain many parts which can affect a magnetic sensor. When deciding the mounting position, it is necessary to consider the types of materials and the amount of current carried in proximity of the magnetic sensor.
Accuracy of an electronic compass depends upon getting clean geomagnetic data from the magnetic sensor output without errors caused by other magnetic elements. These errors need to be canceled by calibration or correction. This document explains magnetometer integration challenges from the mobile equipment point of view, and gives guidelines for the mounting position of the magnetic sensor.