How to get the compass direction from azimuth on Android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 01:46:13

问题


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


回答1:


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




回答2:


You have several examples of implementing a compass on Android.



来源:https://stackoverflow.com/questions/7355679/how-to-get-the-compass-direction-from-azimuth-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!