Location & FindResults not always returning City/State/etc.?

OOT
05-07-2008, 01:28 PM
OK. I hope that I'm just doing something wrong. I've got some code for getting the center point of the map (.width - 6 / 2, .height - 6 / 2). That returns a MapPoint.Location object.

I take that object and I just want to get some "general" location information (from the StreetAddress field). I don't care about the Address information but I do want to know the city, state and postal code for whatever location is the current centerpoint of the map. Here is what I've got and I can't figure out what I'm doing wrong.


''''oMPLoc is a MapPoint.Location set to these coordinates:
''''lat:33.3720721397549 lng: -83.7399965710938
oMPLoc.GoTo()

Dim addressResults As MapPoint.FindResults = _
oMap.ObjectsFromPoint(oMap.LocationToX(oMPLoc), _
oMap.LocationToY(oMPLoc))

Dim o As Object

For Each o In addressResults

If TypeOf o Is MapPoint.Location Then

Dim streetLoc As MapPoint.Location = o

If streetLoc.StreetAddress IsNot Nothing Then

txtCity.Text = streetLoc.StreetAddress.City
txtPostal.Text = streetLoc.StreetAddress.PostalCode
txtState.Text = streetLoc.StreetAddress.Region

End If

End If

Next
Sometimes I run this and I get the information like I should but then sometimes I run it and everything is empty. When I debug and step through the code the StreetAddress object is either empty or contains empty strings for City, Region (State) and PostalCode.

Assuming I have a location based on valid Latitude and Longitude coordinates, is there a better way to get the City, State and PostalCode information? Can anyone see what I'm doing wrong in the code above (VB.NET)?

Any and all help is greatly appreciated. And please speak as plainly as possible as I'm quite the newbie :D

Thank you in advance for any and all help.

Wilfried
05-07-2008, 01:52 PM
Hi,

sometimes there is no result you say, but indeed possible there is just no valid location in the center of the map. you can increase altitude to find one, increasing altitude set the dilusion of precision higher so chance is better there is a valid location.

OOT
05-07-2008, 02:12 PM
Wow. That was fast and it fixed the problem. So I've written it as a Function and if it returns as Nothing then I re-run at higher Altitude ... works like a charm!

Thank you very much for that.

Wilfried
05-07-2008, 02:58 PM
Hi,

Glad it works :) That's what I often do in some occations where it is just necessary to get a location nearby some point.

 
Web mp2kmag.com
mapforums.com