android - 如何从Android上的方位角获取罗盘方向

标签 android sensors android-sensors azimuth

我必须显示用户指向 Android 设备的方向。

我正在使用 Sensor.TYPE_ACCELEROMETERSensor.TYPE_MAGNETIC_FIELD 获取方位角、俯仰角和横滚角。但我能够弄清楚如何从中获取方向(北、南、东、西……)。

请帮忙

谢谢

最佳答案

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

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

您可以看到以下指南针使用加速度计和磁场的示例:http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html

维基百科上的方位角:http://en.wikipedia.org/wiki/Azimuth

关于android - 如何从Android上的方位角获取罗盘方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7355679/

相关文章:

printf - 使用 printf 的 atmel 传感器

Android SensorDirectChannel 不返回任何传感器测量结果

java - 如何根据摇动事件制作文本动画

android - Google Keep 在您的应用程序中列出备注

android - 不小心改了android :Versioncode to a higher value,现在怎么办?

android - 将文件保存在 iOS 应用程序目录中

web-applications - 使用 Web 应用程序的 Service Worker 进行后台地理位置跟踪

Android加速度计校准?

Android Gradle 组常用属性

java - 使用广播在摇晃时启动应用程序