Search code examples
google-mapsgeocodinggoogle-geocodergoogle-geocoding-api

Google Geocoding API always returns a lat long from centre of UK, no matter what search term we use


We've been using this API from quite some time. We could see addresses being returned out of the UK & hence changed the geocoding URL to restrict to UK only.

http://maps.googleapis.com/maps/api/geocode/xml?latLng=54,-2&address=gdfgsdgsd,GB

http://maps.googleapis.com/maps/api/geocode/xml?latLng=54,-2&address=gdfgsdgsd,GB&components=country:GB

Please check the results for both of the above URL's. The first URL returns ZERO_RESULTS which is correct. The second one always returns a lat long from centre of UK, no matter what search term we use.

You can also try replacing the value for 'address' to replicate the issue : 452376452334,^$%^$%^$%,458352462354^$%^$%^


Solution

  • Looks like I have found a way to resolve this. The URL pattern I use now is : http://maps.googleapis.com/maps/api/geocode/xml?address=Leeds,UK|GB

    The below URL now gives ZERO_RESULTs http://maps.googleapis.com/maps/api/geocode/xml?address=gdfgsdgsd,UK|GB

    Also as Joyson suggested, we could also check for the country returned back & display an error message.