kikolino
02-06-2008, 02:13 AM
Hi,
I have the problem that I found an address with the FindAddressResults method and set a pushpin on that point. What i want to know is how to get the lat/long/alt coordinates for that point automaticly via VBA Code in my excel sheet. So I have hundreds of addresses with pushpins and want to have a list with lat/long coordinates for it.
Thx right now,
Kikolino
Wilfried
02-09-2008, 01:58 AM
Hi,
FindAddressResults returns a collection of Location and other objects. So if resultsquality is ok then loop in the result until it is a Location object. Then you can add a pushpin with that Location object and this object has also Latitude / Longitude information, so you have all you need :)
kikolino
02-09-2008, 02:55 AM
Hi Wilfried!
Thank you for your answer. I know what you are meaning and it helped to understand the problem but I still have the problem that I donīt know how to get the lat/long by writing a VBA Code. My code is the following:
Private Sub CommandButton1_Click()
Dim objFindResults As MapPoint.FindResults
Dim objLoc As MapPoint.Location
Dim objPushpin As MapPoint.Pushpin
Dim Bereich As Range
Dim Zelle As Range
Set oApp = CreateObject("MapPoint.Application")
Set objMap = oApp.NewMap
Set objRoute = objMap.ActiveRoute
Dim nCurrentRow As Integer
nCurrentRow = 2
szAddress = Cells(nCurrentRow, 4)
Do While (szAddress <> 0)
szName = Cells(nCurrentRow, 1)
szcity = Cells(nCurrentRow, 3)
szZip = Cells(nCurrentRow, 2)
Set objFindResults = objMap.FindAddressResults(szAddress, szcity, szZip)
Set objLoc = objFindResults(1)
Set objPushpin = objMap.AddPushpin(objLoc, szName)
objPushpin.BalloonState = geoDisplayName
nCurrentRow = nCurrentRow + 1
szAddress = Cells(nCurrentRow, 4)
Loop
And now i want to get the lat/long coordinates for each pushpin and afterwards calcute the distances between them. But I donīt know how...
objPushin...
distance.calculate...
Perhaps you can help me again, that would be great!
Greetz
Kikolino
davidb
02-11-2008, 04:55 AM
To get the latitude and longitude I think all you need is
'Get latitude of this location
Lat = objLoc.Latitude
'Get longitude of this location
Lon = objLoc.Longitude
To get distance then calculate the route and apply
objRoute.Distance …………..for the driving distance
objRoute.DrivingTime …………….for the driving time
objMap.Distance(objLoc1, objLoc2) ………….for the straight line distance
kikolino
02-14-2008, 02:39 AM
Hi davidb!
Thanks for your help! It works now! :)
Greetz
Kikolino
Winwaed
02-14-2008, 08:36 AM
The Latitude and Longitude properties are only guaranteed to be set if you are working with MapPoint 2006.
Earlier versions only set these fields if the object was created with coordinates!
(search this site for "CalcPos" for a cunning solution from Gilles)
Richard