Adrian Sheard
01-18-2007, 02:18 AM
Can anyone provide a solution for this?
Using the MapPoint Control both MP2K2 and MP2K4 return a street address 'underlying' a point of interest e.g. Riverside Cafe, Burbank CA returns 1221 W Riverside Drive, Burbank CA (which is indeed correct). However MP2K6's control (i.e. programmatic access) returns nothing whereas the MP2K6 application manages to display the address in the balloon.
How can I 'persuade' MP2K6's control to provide the street address just like MapPoint app?
Paul Larson
01-18-2007, 09:13 PM
This is a known issue with MapPoint 2006 and has occasionally even been noted with MapPoint 2004.
Perhaps it is due in part to licensing agreements with the POI Data Providers.
The best solution I've come up with is to employ reverse-geocoding techniques to find the nearest address to the POI item.
Here's a VB.Net module which I use to get around it.
The module is based on a very convoluted mixture of the reverse-geocoding articles on mp2kmag.com's website which were originally authored by Walt Cygan and Gilles Kohl. Just pass the POI Location to the function "GetNearestLocationAddress" and you'll get something usable back :)
'------BEGIN CODE-------------
Module modAdvancedAddressFuncs
Public Function GetNearestLocationAddress(ByRef objMap As MapPoint.Map, ByVal OriginalLocation As MapPoint.Location) As MapPoint.Location
'Gets an address for a Location object using reverse-geocoding brute-force
'This code is loosely cased on Walt Cygan's article from mp2kmag.com
Dim objLoc As MapPoint.Location
Dim objResults As MapPoint.FindResults
'Attempt to find an address at (approximately) this SAME position.
'Note this might not actually be the same position, since the current map Altitude
' has an increasing effect on the ObjectsFromPoint() method.
OriginalLocation.GoTo()
objMap.Altitude = 0.01D
objResults = objMap.ObjectsFromPoint(objMap.LocationToX(Origina lLocation), objMap.LocationToY(OriginalLocation))
For Each Result As MapPoint.Location In objResults
If Not (Result.Location.StreetAddress Is Nothing) Then
Return Result.Location
Exit Function
End If
Next Result
'Nothing was found, so recursively attempt to find a "near match."
'Search at points spiralling outward from the original location.
'We search at points in the order of North, South, East, West, NE, SE, NW, SW
' since nearby roads will most likely be "hit" in those locations.
Dim ThisLoc As MapPoint.Location
For DeltaOfs As Double = 0.001D To 0.1D Step 0.001D
For OctagonPosition As Integer = 1 To 8
ThisLoc = TryDeltaLoc(objMap, OriginalLocation, OctagonPosition, DeltaOfs)
If Not (ThisLoc.StreetAddress Is Nothing) Then
'we found a nearby address, so use Routing to find the start address
Return FindAddressByRoute(objMap, OriginalLocation, ThisLoc)
Exit Function
End If
Next OctagonPosition
Next DeltaOfs
noneFound:
'if we got this far, then we haven't gotten any hits, so return nothing
Return Nothing
Exit Function
End Function
Private Function TryDeltaLoc(ByRef objMap As MapPoint.Map, ByVal CenterLoc As MapPoint.Location, ByVal OctagonPosition As Integer, ByVal Offset As Double) As MapPoint.Location
'Try to geocode at a Delta-ed location by octagon position (rotated coordinate quadrant)
Dim Lat, Lng As Double
Lat = CenterLoc.Latitude
Lng = CenterLoc.Longitude
Dim DeltaLoc As MapPoint.Location
Select Case OctagonPosition
Case 1 'north
DeltaLoc = objMap.GetLocation(Lat, Lng + Offset)
Case 2 'south
DeltaLoc = objMap.GetLocation(Lat, Lng - Offset)
Case 3 'east
DeltaLoc = objMap.GetLocation(Lat + Offset, Lng)
Case 4 'west
DeltaLoc = objMap.GetLocation(Lat - Offset, Lng)
Case 5 'NorthEast
DeltaLoc = objMap.GetLocation(Lat + Offset, Lng + Offset)
Case 6 'SouthEast
DeltaLoc = objMap.GetLocation(Lat - Offset, Lng + Offset)
Case 7 'NorthWest
DeltaLoc = objMap.GetLocation(Lat + Offset, Lng - Offset)
Case 8 'SouthWest
DeltaLoc = objMap.GetLocation(Lat - Offset, Lng - Offset)
End Select
'now attempt to reverse geocode at THIS location
DeltaLoc.GoTo()
objMap.Altitude = 0.01D
Dim objResults As MapPoint.FindResults = objMap.ObjectsFromPoint(objMap.LocationToX(DeltaLo c), objMap.LocationToY(DeltaLoc))
For Each Result As MapPoint.Location In objResults
If Not (Result.Location.StreetAddress Is Nothing) Then
Return Result.Location
Exit Function
End If
Next Result
'if we got nothing, still need to return a valid location object,
' so return the original
Return CenterLoc
End Function
Private Function FindAddressByRoute(ByRef objMap As MapPoint.Map, ByVal StartLoc As MapPoint.Location, ByVal NearbyLoc As MapPoint.Location) As MapPoint.Location
Dim Rte As MapPoint.Route = objMap.ActiveRoute
'clear any current route data
If Not (Rte Is Nothing) Then Rte.Clear()
'create the route from the point we're attempting to geocode to a known-good nearby address
Rte.Waypoints.Add(StartLoc)
Rte.Waypoints.Add(NearbyLoc)
Rte.Calculate()
'call a single recursion of the original routine
Return GetNearestLocationAddress(objMap, Rte.Directions.Item(1).Location)
End Function
End Module
'------END CODE-------------
HTH
Paul