PDA

View Full Version : Newbie needs help calculating distance

Tom S.
11-16-2005, 03:09 PM
Hello all. I stumbled across this forum while looking for MapPoint help on the web. I am trying to come up with a way to access MapPoint (2001) via a function in an Excel module and calculate the distance between locations in two different cells. I can use the Distance method in conjunction with GetLocation method only if I start with lat,long,alt. Problem is, I want to use city,state,country and this seems to require the Find method. Is there a way to work around this? Thanks for any ideas that you can offer. Here is a general idea. strPoint1 and strPoint2 will eventually be Excel cell addresses. Thanks, Tom

Function StraightLineDist(strPoint1, strPoint2)
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLoc(1 To 4) As MapPoint.Location

Dim dblDistance As Double

Set objMap = objApp.NewMap

'Get two known locations
Set objLoc(3) = objMap.Find("Seattle, WA, United States") 'Seattle, WA
Set objLoc(4) = objMap.Find("Redmond, WA, United States") 'Redmond, WA

Set objLoc(1) = objMap.GetLocation(47.75399, -121.97436, 100) 'Seattle, WA
Set objLoc(2) = objMap.GetLocation(47.6779, -122.11032, 100) 'Redmond, WA

'Retrieve the distance
StraightLineDist = objMap.Distance(objLoc(1), objLoc(2))

End Function

Wilfried
11-17-2005, 07:26 AM
Hi,

This article http://www.mp2kmag.com/articles.asp?ArticleID=13&key=extract.lat.lon describes how to calculate coordinates from a location object. I think this is what you need.