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 6 of 6

Latitude & Longitude into a function

This is a discussion on Latitude & Longitude into a function within the MapPoint Desktop Discussion forums, part of the Map Forums category; I have been using the following code to help me determine the distances between stores. It works great, but I ...

  1. #1
    pinem1 is offline Junior Member White Belt
    Join Date
    Sep 2005
    Posts
    10

    Latitude & Longitude into a function

    I have been using the following code to help me determine the distances between stores. It works great, but I want to be more accurate and I want to use Latitude and Longitude.

    Can someone help me modify the code so I can bring in a latitude and longitude for each of the two locations and then have it tell me the distance between the two?


    Function MPRouteDist(iMPType As Integer, ParamArray WPoints())

    Dim objApp As New MapPoint.Application
    Set objMap = objApp.ActiveMap

    With objMap.ActiveRoute
    For Each wpoint In WPoints
    .Waypoints.Add objMap.FindResults(wpoint).Item(1)
    Next
    .Waypoints.Item(1).SegmentPreferences = iMPType
    .Calculate
    MPRouteDist = Application.Round(CStr(.Distance), 5)
    End With

    objMap.Saved = True
    End Function

    A little bonus help as well. Is there a way to take the same information and have Mappoint tell me the minutes it would take to drive between the two locations?

    Any and all help is greatly appreciated! Thanks

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Latitude & Longitude into a function

    Well let's tackle the first one first.

    Waypoint.Add is expecting a Location or Pushpin object, see the Help file.

    Actually, check out the help file for Add Waypoints, they have an example right there --

    Code:
     
      Set objLoc = objMap.GetLocation(47.6008, -122.334, 100)
     
      'Add a waypoint using the location and give it a name   
      objRoute.Waypoints.Add objLoc, "Seattle"
    objLoc is a MapPoint.Location.

    Eric

  3. #3
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Latitude & Longitude into a function

    I didn't test this but see how this works for you.

    Let us know.

    Code:
     
    Function MPRouteDist(iMPType As Integer, LatitudeStart As Long, LongitudeStart As Long, LatitudeEnd As Long, LongitudeEnd As Long )
    
      Dim objApp As New MapPoint.Application
      Set objMap = objApp.ActiveMap
      Dim objLocStart As MapPoint.Location
      Dim objLocEnd As MapPoint.Location
     
      Set objLocStart = objMap.GetLocation(LatitudeStart, LongitudeStart, 100)
      Set objLocEnd = objMap.GetLocation(LatitudeEnd, LongitudeEnd, 100)
    
      With objMap.ActiveRoute
        .Waypoints.Add objLocStart
        .Waypoints.Add objLocEnd
        .Waypoints.Item(1).SegmentPreferences = iMPType
        .Calculate
        MPRouteDist = Application.Round(CStr(.Distance), 5)
      End With
    
      objMap.Saved = True
    End Function

  4. #4
    pinem1 is offline Junior Member White Belt
    Join Date
    Sep 2005
    Posts
    10

    Re: Latitude & Longitude into a function

    my results all came in at 0. i don't think it worked quite right

  5. #5
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Latitude & Longitude into a function

    Hmm, it worked for me.

    I put this in the Excel debugger:

    ? MPRouteDist(1,40,-90,41,-90)
    79.8462

    Also, see the attached spreadsheet and screenshot.

    hope this helps!

    Eric
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    pinem1 is offline Junior Member White Belt
    Join Date
    Sep 2005
    Posts
    10

    Re: Latitude & Longitude into a function

    I think I fixed it. The Latitudes and Longitudes I am using have multiple decimals points. So I changed Long to Double and it seems to work now.

    Thanks for all of your help

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to get latitude and longitude
    By ma2005pp in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 09-28-2005, 02:57 AM
  2. Latitude and Longitude
    By virgilar in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-21-2005, 02:01 PM
  3. Latitude and Longitude
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-25-2003, 01:52 PM
  4. NMEA latitude/longitude and mappoint latitude/longitude
    By muurman in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 11-22-2003, 05:42 AM
  5. Link to a GPS Latitude and Longitude?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 11-03-2003, 11:12 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