如何在Android上从方位角获取指南针方向 [英] How to get the compass direction from azimuth on Android

查看:850
本文介绍了如何在Android上从方位角获取指南针方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to display which direction the user is pointing the Android device.

我正在使用Sensor.TYPE_ACCELEROMETERSensor.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);

您可以看到以下使用加速度计和磁场的指南针示例:

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上从方位角获取指南针方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆