 Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.   ## calculate straight line distance

This is a discussion on calculate straight line distance within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi to all, i'd like to know a method to calculate straight line distance between two points. To add a ...

1. Junior Member White Belt
Join Date
Dec 2006
Posts
4

## calculate straight line distance

Hi to all,

i'd like to know a method to calculate straight line distance between two points.

To add a line i do

and distance?

Thank you for any suggestion,

Francesco  Reply With Quote

2. Senior Member Blue Belt
Join Date
Oct 2003
Location
London
Posts
290

## Re: calculate straight line distance

Think this works in VB6 when you haven't calculated a route

Distance# = oMap.Distance(location1, location2)

There's a good example on MapPoint help under 'Distance Method' using both VB6 and C#

Rgds, David  Reply With Quote

3. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433

## Re: calculate straight line distance

Hi Francesco,

In addition to the reply of David, if you have to do it with only latitude / longitude you can use this formula:

Code:
```public static int CalcDistance(double lat1, double lon1, double lat2, double lon2, out int heading)
{
double lat = lat2 - lat1;
double lon = (lon2 - lon1) * Math.Cos(Tools.deg2rad((int)((lat1 + lat2) / 2)));
double dist = Math.Sqrt(lat * lat + lon * lon);

if (lon < 0) // Western direction

return (int)(dist * 60 * 1852);
}

{
return degree * Math.PI / 180;
}

{
return (int)(rad * 180 / Math.PI);
}```  Reply With Quote

There are currently 1 users browsing this thread. (0 members and 1 guests)

calculate, distance, line, straight 