问题描述
我必须显示用户指向Android设备的方向.
I have to display which direction the user is pointing the Android device.
我正在使用Sensor.TYPE_ACCELEROMETER
,Sensor.TYPE_MAGNETIC_FIELD
来获取方位角,俯仰和横滚.但是我能够弄清楚如何从中获得方向(北,南,东,西...).
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.
请帮助
谢谢
推荐答案
要指向北方,您可以计算以度为单位的旋转度:
To point the north you can calculate a rotation in degrees :
float rotation = -azimut * 360 / (2 * 3.14159f);
您可以看到以下使用加速度计和磁场的指南针示例: http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html
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
Wikipédia上的方位角: http://en.wikipedia.org/wiki/方位角
Azimuth on Wikipédia : http://en.wikipedia.org/wiki/Azimuth
这篇关于如何在Android上从方位角获取指南针方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!