Android:Location.distanceTo 无法正常工作?

发布于 2024-07-13 06:22:23 字数 1144 浏览 6 评论 0原文

我在使用 Location.distanceTo 方法计算距离时遇到问题。

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)";
    }
}

有人可以告诉我为什么我的距离计算结果显示 12,637,795 米吗?

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)";
    }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2024-07-20 06:22:23

您应该修改行:

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

并删除行:

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

You should Modify lines:

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

And remove the lines:

aLocation.set(aLocation);
bLocation.set(bLocation);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文