我试图实现一个箭头,使用方向传感器来指向特定的位置. 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.jb51.cc/android/312831.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。