【问题标题】:Android : Location.distanceTo not working correctly?Android:Location.distanceTo 无法正常工作?
【发布时间】:2010-10-06 14:09:20
【问题描述】:

我在使用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 米?

【问题讨论】:

    标签: android location distance


    【解决方案1】:

    你应该修改行:

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

    并删除行:

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

    【讨论】:

    • 谢谢,看来我在其他一些事情(反向地理编码)上遇到了一些问题。
    猜你喜欢
    • 2016-12-01
    • 1970-01-01
    • 2016-09-01
    • 2012-07-11
    • 2018-04-08
    • 2017-04-20
    • 2018-10-02
    • 2016-09-04
    • 2011-11-13
    相关资源
    最近更新 更多