2010-02-15 60 views

回答

5

使用haversine公式http://en.wikipedia.org/wiki/Haversine_formula

僞代碼:

R = 6371; // corrected earth radius, km 
dLat = degToRad(lat2-lat1); 
dLon = degToRad(lon2-lon1); 
a = sin(dLat/2) * sin(dLat/2) + 
     cos(degToRad(lat1)) * cos(degToRad(lat2)) * 
     sin(dLon/2) * sin(dLon/2); 
c = 2 * atan2(sqrt(a), sqrt(1-a)); 
distance = R * c; 

degToRad輩分轉換爲弧度,例如見here

相關問題