【问题标题】:Distance between two locations isn't right两个位置之间的距离不对
【发布时间】:2011-03-16 12:34:06
【问题描述】:

我已经使用http://www.movable-type.co.uk/scripts/latlong.html 上的算法来找到两点之间的距离。

我的两点是

long1 = 51.507467;
lat1 = -0.08776;

long2 = 51.508736;
lat2 = -0.08612;

根据Movable Type Script的答案是0.1812km

我的应用程序给出的结果 (d) 为 0.230 公里

检查Haversine公式:http://www.movable-type.co.uk/scripts/latlong.html

    double R = 6371; // earth’s radius (mean radius = 6,371km)
    double dLat =  Math.toRadians(lat2-lat1);

    double dLon =  Math.toRadians(long2-long1); 
    a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * 
            Math.sin(dLon/2) * Math.sin(dLon/2); 
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
    double d = R * c;

【问题讨论】:

    标签: android maps distance haversine


    【解决方案1】:

    为什么要重新发明您自己的距离计算器,Location 类中内置了一个。

    退房

    distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) 
    Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them.
    

    【讨论】:

      【解决方案2】:

      您的实现是正确的。给定这些经度和纬度的距​​离应产生0.230 km 的距离。然而,坐标的正常输入是(纬度,经度)。将它们放在后面(经度、纬度)会产生不正确的距离 0.1812 km

      【讨论】:

      • 哦...有点尴尬。感谢您的帮助:)
      【解决方案3】:
      public double CalculationByDistance(GeoPoint StartP, GeoPoint EndP) {  
        double lat1 = StartP.getLatitudeE6()/1E6;  
        double lat2 = EndP.getLatitudeE6()/1E6;  
        double lon1 = StartP.getLongitudeE6()/1E6;  
        double lon2 = EndP.getLongitudeE6()/1E6;  
        double dLat = Math.toRadians(lat2-lat1);  
        double dLon = Math.toRadians(lon2-lon1);  
        double a = Math.sin(dLat/2) * Math.sin(dLat/2) +  
           Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *  
           Math.sin(dLon/2) * Math.sin(dLon/2);  
        double c = 2 * Math.asin(Math.sqrt(a));  
        return Radius * c;  
       }  
      

      Ally你的概念是对的。这行可能有点变化double c = 2 * Math.asin(Math.sqrt(a));

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-26
        • 1970-01-01
        相关资源
        最近更新 更多