Here are a few methods that calculate distance between 2 points of Latitude
and Longitude. Calculations of distance between points of Latitude and
Longitude are always approximate, as the surface of the earth is curved, and
the earth is an oblate spheroid, rather than a sphere, and therefore,
distance is distance along a curve that varies from one point on the surface
to another. There are methods of calculating distance that are more or less
accurate, and they become increasingly complex as they become increasingly
accurate. The following methods treat the earth as a sphere, and use a mean
earth radius (average of the radius based upon the radius at the poles and
equator). They should be accurate enough for this purpose.
Note that there is a reference to a struct called "LatLong," which is simply
a struct containing 2 doubles:
public const double MeanEarthRadiusFeet = 20903215.2;
public static double DistanceRadians(LatLong PointA, LatLong PointB)
{
double aLat, aLong, bLat, bLong;
aLat = PointA.Lat * (Math.PI / 180);
aLong = PointA.Long * (Math.PI / 180);
bLat = PointB.Lat * (Math.PI / 180);
bLong = PointB.Long * (Math.PI / 180);
return Math.Acos(Math.Cos(aLat) * Math.Cos(bLat) *
Math.Cos(aLong - bLong)
+ Math.Sin(aLat) * Math.Sin(bLat));
}
public static double Distance(LatLong PointA, LatLong PointB)
{
double radians = DistanceRadians(PointA, PointB);
return radians * MeanEarthRadiusFeet; // Distance in feet
(convert to whatever)
}
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net