How to get the compass direction from azimuth on Android

Android_enthusiast picture Android_enthusiast · Sep 9, 2011 · Viewed 11.1k times · Source

I have to display which direction the user is pointing the Android device.

I am using Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_MAGNETIC_FIELD to get the azimuth, pitch, roll. But I am to able to figure out how to get directions (North, south, east , west,...) from this.

Please help

Thanks

Answer

Yves M. picture Yves M. · Apr 14, 2014

To point the north you can calculate a rotation in degrees :

float rotation = -azimut * 360 / (2 * 3.14159f);

You can see the following compass example which make uses of accelerometer and magnetic field : http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html

Azimuth on Wikipédia : http://en.wikipedia.org/wiki/Azimuth