This project is read-only.

Direction - Distance

Aug 12, 2010 at 8:16 PM
Hi, Can you show me an example for calculating the distance? I ma using your control to get directions and what I would like to do is find the distance between those two points or the total route. Thanks Dee4PA
Sep 28, 2010 at 10:40 AM

try this.

public static decimal CalculateDistanceBetweenGPSCoordinates(decimal _lon1, decimal _lat1, decimal _lon2, decimal _lat2) { double lon1 = (double)_lon1; double lon2 = (double)_lon2; double lat1 = (double)_lat1; double lat2 = (double)_lat2; const double R = 3956; const double degreesToRadians = Math.PI / 180; //convert from fractional degrees (GPS) to radians lon1 *= degreesToRadians; lat1 *= degreesToRadians; lon2 *= degreesToRadians; lat2 *= degreesToRadians; double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.Pow(Math.Sin(dlat / 2), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(dlon / 2), 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double d = R * c; d = d * 1.852; return (decimal)d; }