Hi to all,
i'd like to know a method to calculate straight line distance between two points.
To add a line i do
map.Shapes.addLine(location1,location2)
and distance?
Thank you for any suggestion,
Francesco
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 ...
Hi to all,
i'd like to know a method to calculate straight line distance between two points.
To add a line i do
map.Shapes.addLine(location1,location2)
and distance?
Thank you for any suggestion,
Francesco
Think this works in VB6 when you haven't calculated a route
oMap.Shapes.AddLine location1, location2
Distance# = oMap.Distance(location1, location2)
There's a good example on MapPoint help under 'Distance Method' using both VB6 and C#
Rgds, David
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); heading = Tools.rad2deg(Math.Acos(lat / dist)); if (lon < 0) // Western direction heading = 360 - heading; return (int)(dist * 60 * 1852); } private static double deg2rad(int degree) { return degree * Math.PI / 180; } private static int rad2deg(double rad) { return (int)(rad * 180 / Math.PI); }
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
There are currently 1 users browsing this thread. (0 members and 1 guests)