两个地点之间的距离不对

All*_*lly 5 maps android distance haversine

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

我的两点是

long1 = 51.507467;
lat1 = -0.08776;

long2 = 51.508736;
lat2 = -0.08612;
Run Code Online (Sandbox Code Playgroud)

根据Movable Type Script,答案是0.1812km

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

检查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;
Run Code Online (Sandbox Code Playgroud)

Pen*_*m10 9

为什么重新发明自己的距离计算器,有一个内置于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.
Run Code Online (Sandbox Code Playgroud)