How to get the compass direction from azimuth on Android
Asked Answered
O

2

6

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

Overpowering answered 8/9, 2011 at 23:31 Comment(0)
I
2

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

Imprecation answered 14/4, 2014 at 13:20 Comment(0)
M
1

You have several examples of implementing a compass on Android.

Myers answered 8/12, 2011 at 23:43 Comment(3)
Your sample use TYPE_ORIENTATION which is deprecatedImprecation
Take into account that samples are from the year 2010, and the answer was published in 2011. There are lots of things that have changed in the Android ecosystem in the last three years.Myers
Yes sure, and don't take it personal. It's just that it's now deprecated. I want to add usefull informations for future readers :)Imprecation

© 2022 - 2024 — McMap. All rights reserved.