Following is the flawed code:
Code:
1: location = map.GetLocation(latitude, longitude, altitude);
2: location.goTo();
3: results = map.ObjectsFromPoint(map.locationToX(location), map.locationToY(location));
4: foreach(object sample in results)
5: {
6: if(sample is Location)
7: {
8: if(!findAddress || sample.StreetAddress != null)
9: return sample;
10: }
11: }
Followed by another method for finding the address if that one failed. The problem occured on line #3. Sometimes MapPoint will return the center of a timezone as the closest object. I think this may be what Gilles Kohl refered to as "'so close, but yet so far' syndrome" in "Reverse Geocoding, Another Method". I changed the code so something similar to the following:
Code:
1: location = map.GetLocation(latitude, longitude, altitude);
2: location.goTo();
3: results = map.ObjectsFromPoint(map.locationToX(location), map.locationToY(location));
4: if(findAddress)
5: {
6: foreach(object sample in results)
7: {
8: if(sample is Location)
9: {
10: if(sample.StreetAddress != null)
11: return sample;
12: }
13: }
14: }
15: return location;
Now the original location is returned if no address can be found. Keep this in mind. This code will not find an address for all points, rather in a "don't care" situation it will try to find an address. Should it fail, the name of the location will be the GPS coordinates that it was created from.