I am having an issue with Windows Phone 8 Geocoding. Using Microsoft.Phone.Maps.Services.QuerycodeQuery, if I use a full Canadian Postal Code (M5G 1Z4) I get no results. If I use only the first 3 characters (M5G) I get the expected results.
I am not doing anything specific with the data, just passing it to Microsoft for geocoding. Is there a specific reason behind this or is there another way to lookup locations?
Code:
Geocode = new GeocodeQuery()
{
SearchTerm = LocationString,
GeoCoordinate = UserCoordinates ?? new GeoCoordinate(),
MaxResultCount = 1
};
Geocode.QueryCompleted += GetStringLocation_QueryCompleted;
Geocode.QueryCompleted += CleanupGeocode;
Geocode.QueryAsync();
Although this doesn’t address the limitation that appears to be in the mapping service’s geocode function it is a little workaround that works for me…
When the
GetStringLocation_QueryCompletedfunction returns 0 results I run a regex to check if the search is a valid postal code. If it is one, then I grab the first 3 characters and re-run the geocode.One thing to make sure of with this approach is that you check to make sure the geocode is not running (IsBusy) when the secondary dispose function is called (if you do it in a separate function)
Regex (Utility.IsPostalCode):
Within GetStringLocation_QueryCompleted
GetStringLocationwould be the function that contains the code that is in the question which accepts a string.