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

## 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. 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
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. ## 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
objLoc is a MapPoint.Location.

Eric

3. ## 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.Item(1).SegmentPreferences = iMPType
.Calculate
MPRouteDist = Application.Round(CStr(.Distance), 5)
End With

objMap.Saved = True
End Function```

4. 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. ## 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

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

##### Users Browsing this Thread

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

#### Posting Permissions

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