Distance Route (km)

Apr 3, 2009 at 10:58 AM

I suggest to add a length of the route:

In MapRoute:

public double Distance
{
get
{
var distance = 0.0;
for (var i = 1; i < Points.Count; i++)
{
distance += Distance.Calc(Points[i - 1].Lat, Points[i - 1].Lng, Points[i].Lat,
Points[i].Lng);
}

return distance;
}
}

public static class Distance
{
public static double Calc(double lat1, double lng1, double lat2, double lng2)
{
var dLat1InRad = lat1 * (Math.PI / 180);
var dLong1InRad = lng1 * (Math.PI / 180);
var dLat2InRad = lat2 * (Math.PI / 180);
var dLong2InRad = lng2 * (Math.PI / 180);
var dLongitude = dLong2InRad - dLong1InRad;
var dLatitude = dLat2InRad - dLat1InRad;
var a = Math.Pow(Math.Sin(dLatitude / 2), 2) + Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) * Math.Pow(Math.Sin(dLongitude / 2), 2);
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
const double kEarthRadiusKms = 6376.5;
var dDistance = kEarthRadiusKms * c;
return dDistance;
}
}

Coordinator
Apr 3, 2009 at 11:50 AM
it's direct line, real route has its own distance calculated by google, anyway we can use this function to calculate distance of sum of route splits
Apr 3, 2009 at 12:24 PM
This is not a direct line. It is calculated by route of coordinates. Google feels the same way.