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..

  • 1
    Can you post your code? Are you looking for driving distance or "as the crow flies" distance? – MJ Hufford May 01 '13 at 10:45
  • I used this implementation, worked for me. http://danielsaidi.wordpress.com/2011/02/04/geo-location-in-c-calculate-distance-and-bearing-between-two-positions/ – shakib May 01 '13 at 12:26

1 Answers1

0

Why c# if you can achieve it by javascript

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;
Pavan Kumar
  • 190
  • 2
  • 8