MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




calculate straight line distance

This is a discussion on calculate straight line distance within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 12-13-2006
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

map.Shapes.addLine(location1,location2)

and distance?

Thank you for any suggestion,

Francesco
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 12-13-2006
Senior Member
Green Belt
 
Join Date: Oct 2003
Location: London
Posts: 102
Re: calculate straight line distance

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 12-14-2006
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,094
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);

    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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
calculate, distance, line, straight


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/calculate-straight-line-distance-5482.html

Posted By For Type Date
Discovering MapPoint Map Printing Capabilities - MapPoint Articles - MP2K Magazine This thread Refback 12-19-2006 09:15 AM
Pushpin Tool Add-in - MP2K Magazine This thread Refback 12-13-2006 08:38 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Points in a straight line Dazzer MapPoint 2006/2009 Discussion 6 05-25-2004 11:27 AM
[VB6 + MP2K] How to calculate distance between... Vincent BENNER MapPoint 2006/2009 Discussion 1 11-19-2003 11:59 AM
how to calculate distance between 2 towns Anonymous MapPoint 2006/2009 Discussion 3 06-06-2003 02:51 PM
So how do i get it to calculate teh distance betwe.... Anonymous MapPoint 2006/2009 Discussion 1 12-19-2001 07:42 AM
I would like to calculate the distance from multip.... Anonymous MapPoint 2006/2009 Discussion 1 10-31-2001 03:39 AM


All times are GMT -5. The time now is 07:31 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

French Ski Holidays
French ski holidays will suit all skiers and most taste buds too. There is a huge range of accommodation from self-catered or catered chalets to all-inclusive luxury hotels.

Spain Weather
Check Spain Weather before you travel. We provide information on Spain including weather, flights and accommodation.

Holidays Italy
Book your holidays in Italy. Italy has a great climate and the beaches to go with it. Book a great deal for great value online at dealchecker.co.uk.

Antigua Holidays
We have the most popular Antigua holidays at highly competitive prices at The Holiday Place. Book a break in sunny Antigua today.

Tunisia
Tunisia enjoys excellent weather, golden beaches and a beautiful blue sea. Moving away from the beach you will find a country that has a rich and varied past. Discover the secrets of history yourself by exploring all the ruins.

Inclusive package holidays
Choose one of the many inclusive package holidays at Travel.co.uk and save a lot of trouble and money too!

Holidays to Sharm el Sheikh
Want to visit the Sinai peninsula? We can help. Info on holidays to Sharm el Sheikh, only at On The Beach.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52