安卓:Location.distanceTo不能正常工作?

编程入门 行业动态 更新时间:2024-10-10 08:21:32
本文介绍了安卓:Location.distanceTo不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题,使用Location.distanceTo方法计算距离。

I am having an issue calculating distance using the Location.distanceTo method.

private class MyLocationOverlay1 extends MyLocationOverlay { @Override public void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) super.drawMyLocation(canvas,mapView,lastFix,myLocation,when); Location bLocation = new Location("reverseGeocoded"); bLocation.setLatitude(FindList.gpslat); // Value = 3.294391E7 bLocation.setLongitude(FindList.gpslong); // Value = -9.6564615E7 Location aLocation = new Location("reverseGeocoded"); aLocation.setLatitude(myLocation.getLatitudeE6()); // Value = 3.2946164E7 aLocation.setLongitude(myLocation.getLongitudeE6()); // Value = -9.6505141E7 aLocation.set(aLocation); // Don't think I need this bLocation.set(bLocation); // Don't think I need this either int distance = (int)aLocation.distanceTo(bLocation); // Value = 12637795 ??? String str = " (" + String.valueOf(distance) + " meters)"; } }

谁能告诉我为什么我的距离计算是显示12637795米?

Can someone tell my why my distance calculation is showing 12,637,795 Meters?

推荐答案

您应该修改行:

aLocation.setLatitude(myLocation.getLatitudeE6() / 1e6); aLocation.setLongitude(myLocation.getLongitudeE6() / 1e6);

和删除行:

aLocation.set(aLocation); bLocation.set(bLocation);

更多推荐

安卓:Location.distanceTo不能正常工作?

本文发布于:2023-11-27 10:02:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不能正常   工作   Location   distanceTo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!