Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

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

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 3 of 3

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. #1
    frizzello is offline 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

  2. #2
    davidb is offline 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

    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

  3. #3
    Wilfried is offline 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);
    
        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);
    }

Thread Information

Users Browsing this Thread

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

Similar Threads

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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