我已經使用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.1812公里
我的應用程序給出結果(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;
會試試:) – Ally 2010-07-15 18:41:04
它工作!謝謝 – Ally 2010-07-15 18:51:36