I`d like calculate the distance of two geo points. the points are given in longitude and latitude.
the coordinates are:
point 1: 36.578581, -118.291994
point 2: 36.23998, -116.83171
here a website to compare the results:
http://www.movable-type.co.uk/scripts/latlong.html
here the code I used from this link: Calculate distance between two points in google maps V3
const double PIx = Math.PI; const double RADIO = 6378.16; /// /// Convert degrees to Radians /// /// Degrees /// The equivalent in radians public static double Radians(double x) { return x * PIx / 180; } /// /// Calculate the distance between two places. /// /// /// /// /// /// public static double DistanceBetweenPlaces(double lon1, double lat1, double lon2, double lat2) { double R = 6371; // km double dLat = Radians(lat2 - lat1); double dLon = Radians(lon2 - lon1); lat1 = Radians(lat1); lat2 = Radians(lat2); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double d = R * c; return d; } Console.WriteLine(DistanceAlgorithm.DistanceBetweenPlaces(36.578581, -118.291994, 36.23998, -116.83171));
the issue is that I get two different results.
my result: 163,307 km
result of the website: 136 km
any suggestions???
torti