Search code examples
bing-mapspostal-code

Partial postcode returns the correct result on Bing maps while the complete postcode doesn't


Why is it when I request some postcodes from Bing maps I get an incorrect coordinates http://dev.virtualearth.net/REST/v1/Locations?postalCode=IM1+1LD&countryRegion=GB&o=xml&key=MY_BING_KEY

While when I request it using this I get the correct ones http://dev.virtualearth.net/REST/v1/Locations?postalCode=IM1&1LD&countryRegion=GB&o=xml&key=MY_BING_KEY

i.e. when I send IM1+1LD as a postalcode incorrect results are returned, while sending IM1&1LD returns the correct results in the response.


Solution

  • The + indicates your are escaping rather than encoding your query. The plus should be %20 instead. Also, in the UK postal codes are a special case. I recommend searching for them using a query search instead like this: http://dev.virtualearth.net/REST/v1/Locations?q=IM1%201LD&o=xml&key=YOUR_KEY

    You can find additional tips on use the REST services here: https://blogs.bing.com/maps/2013/02/14/bing-maps-rest-service-tips-tricks