2

i am going to develop a location service app i have the application part now i have the work on server side for this i have to calculate the distance between 2 points
for ex(point 1 to point 2 distance = 1 km) and i have got a code when i tried implementing the code shows wrong distance actual km is 1 but the code shows 300 meters.

Can anybody say me why this happens?

Thank you..

4

1 回答 1

0

如果可以通过 javascript 实现,为什么选择 c#

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;
于 2013-05-01T10:45:46.830 回答