且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android上从方位角获取指南针方向

更新时间:2023-02-09 19:51:47

要指向北方,您可以计算以度为单位的旋转度:

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

Wikipédia上的方位角: http://en.wikipedia.org/wiki/方位角

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