title: How to transform Android magnetometer readings to the the world's coordinate space?
body: <p>I am writing some programming on the Android sensors, where I am confused by the readings of magnetometer sensor.</p>
  
  <p>Magnetometer reports the magnetic strengths on the three <strong>axes of the phone</strong>. And I observe that at a same location, if the phone's heading changes, the magnetic readings dramatically change.
  In my understand, however, the earth's magnetic field at a specific location should be relative stable, regardless of the phone's placement gesture.</p>
  
  <p>So, my question is, is there any way to transform the raw readings from the 3-axis magnetometer sensor to the <strong>world's coordinate system</strong>? The accelerometer and orientation data are also available on mobile phones. If so, I suspect the transformed magnetism should be the same even the phone's heading direction changes.</p>
  
  <p>I have referred to the Android source codes, specially, the getOrientation() function and the getRotationMatrix() function. I hoped to get some help from their code implementation. But I did not understand very well. Could someone give any explains on the algorithm principle of these functions?</p>
  
  <p>Link to the code of the functions: <a href="http://www.netmite.com/android/mydroid/cupcake/frameworks/base/core/java/android/hardware/SensorManager.java" rel="nofollow">http://www.netmite.com/android/mydroid/cupcake/frameworks/base/core/java/android/hardware/SensorManager.java</a></p>
  
  <p>Thanks! I am really anxious to the solution to this question.</p>