Distances 'as the crow flies'

TRK
01-16-2007, 02:01 PM
How do I calculate the straight line distances between two locations?

Paul Larson
01-16-2007, 04:34 PM
Try googling for "Great Circle Distance"

An implementation using latitude/longitude points in VB.Net would be:
Calculate Distance and Radius in VB.NET - Visual Basic , VB.NET (http://www.a1vbcode.com/snippet-3557.asp)

Wilfried
01-19-2007, 01:16 PM
Hi,

Here is a code sample in Delphi:

function TRefPoints.GetDistance(Lat1, Lon1, Lat2, Lon2: double): integer;
var
Lat, Lon, Dist: double;
begin
Lat := Lat2 - Lat1;
Lon := (Lon2 - Lon1) * Cos(DegToRad((Lat1 + Lat2) / 2));
Dist := Hypot(Lat, Lon);
Result := Round(Dist * 1.852 * 60000); // meters
end;

Paul Larson
01-19-2007, 01:36 PM
Of course, since this is MapPoint we're dealing with...
Look at the methods

Map.Distance(Loc1,Loc2)
and
Location.DistanceTo(Loc)

Can't believe I didn't mention this in my first reply.
[Slaps head]

Wilfried
01-20-2007, 03:25 AM
Hi Paul,

Agreed, but the latter is very slow. If it is needed to do many calcultions at once then own written is mutch faster.

 
Web mp2kmag.com
mapforums.com