android – 使用方向传感器指向特定位置

前端之家收集整理的这篇文章主要介绍了android – 使用方向传感器指向特定位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图实现一个箭头,使用方向传感器来指向特定的位置. Google Places会在ListView中为其找到的每个地方实现此箭头.

我设法得到方位角,但是给出一个位置,我不知道如何继续计算我需要的角度.此外,我需要从北方和北极的转换.有人有这样的实现的例子吗?

提前致谢.

解决方法

解决
float azimuth = // get azimuth from the orientation sensor (it's quite simple)
Location currentLoc = // get location from GPS or network
// convert radians to degrees
azimuth = Math.toDegrees(azimuth);
GeomagneticField geoField = new GeomagneticField(
             (float) currentLoc.getLatitude(),(float) currentLoc.getLongitude(),(float) currentLoc.getAltitude(),System.currentTimeMillis());
azimuth += geoField.getDeclination(); // converts magnetic north into true north
float bearing = currentLoc.bearingTo(target); // (it's already in degrees)
float direction = azimuth - bearing;

如果要绘制箭头或其他东西来指向方向,请使用canvas.rotate(–irection).我们传递一个负面的参数,因为画布旋转是逆时针的.

原文链接:https://www.f2er.com/android/312831.html

猜你在找的Android相关文章