I've read alot about reverse geocoding and I've found that many people is still asking how to translate lat and lon values to an address.
I think it's so strange that Mappoint doesn't have a simple way to do that!
However I've tried to write some code in visual basic and I'd like to share it with everybody. Maybe it can be improved or somebody can tell me if I'm doing something wrong.
I have tried it with Mappoint Europe 2004 and 2006 and it works fine.
Actually I use it for a security and logistic application at my work.
Giacomo from Italy
Code:Public Function find_address(lat As Double, lon As Double, objMap As MapPointctl.Map, pushpin_name As Variant, iteration As Integer) As String Dim objLoc As MapPointctl.Location Dim objResults As MapPointctl.FindResults Dim objpushpin As MapPointctl.Pushpin vect1 = Array(0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2) vect2 = Array(0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0) If iteration = 11 Then GoTo fine Set objLoc = objMap.GetLocation(lat + vect1(iteration) / 300, lon + vect2(iteration) / 300, 10) Set objResults = objMap.ObjectsFromPoint(objMap.LocationToX(objLoc.Location), objMap.LocationToY(objLoc.Location)) Set objpushpin = objMap.FindPushpin(pushpin_name) If (pushpin_name <> " ") Then Set objpushpin = objMap.AddPushpin(objLoc) objpushpin.Symbol = 82 objpushpin.Highlight = True objpushpin.Name = pushpin_name objpushpin.BalloonState = 1 End If ' FIND THE ADDRESS For Each oObj In objResults If oObj Is Nothing = False Then If TypeOf oObj Is MapPointctl.Location Then Set objLoc = oObj If objLoc.StreetAddress Is Nothing = False Then luogo = objLoc.StreetAddress If luogo <> "" Then find_address = luogo Exit Function End If End If End If Next oObj ' IF I DON'T FIND ANYTHING I ITERATE iteration = iteration + 1 If luogo = "" Then Call find_address(lat, lon, objMap, " ", iteration) End If fine: ' IF I STILL HAVEN'T FOUND ANYTHING AFTER ALL ITERATIONS I TAKE ALL I'VE GOT If luogo = "" Then Set objLoc = objMap.GetLocation(Val(lat) + vect1(10) / 300, Val(lon) + vect2(10) / 300) Set objResults = objMap.ObjectsFromPoint(objMap.LocationToX(objLoc.Location), objMap.LocationToY(objLoc.Location)) For Each oObj In objResults If Val(oObj.Name) > 0 Then Else If Len(RTrim(luogo)) > 2 Then luogo = luogo + " - " + oObj.Name Else luogo = oObj.Name End If End If Next oObj End If find_address = luogo End Function