Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google geocoding API returns ZERO_RESULTS for postal code

I am trying to geocode user entered data using the Google maps API, and got an error for the Australian postal code "2010"

maps.google.com/maps/api/geocode/json?components=country:AU|postal_code:2010

However, if I search in Google maps, I get a result. Am I doing something wrong in my request?

like image 858
ShIxtan Avatar asked May 08 '18 00:05

ShIxtan


2 Answers

Your request is completely OK, but unfortunately, Google experience issues with searching 4-digit postal codes. This bug has already been reported in Google issue tracker and you can see it here:

4-digit postal codes are hard to geocode (AT, AU, BE, DK, NZ, SI)

I would suggest starring the bug to add your vote and subscribe to further notifications from Google.

Also you can see that suggested workaround by Google is using place autocomplete request with types (region) and country components filter.

So, in your case you can run the following query

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=2010&types=(regions)&components=country%3AAU&key=YOUR_API_KEY

It will return a place ID for postal code 2010: ChIJ3QyubXuuEmsREIe6P2t9ARw

And you can use geocoding with place ID to get required information

https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ3QyubXuuEmsREIe6P2t9ARw&key=YOUR_API_KEY

I hope this helps!

like image 125
xomena Avatar answered Oct 10 '22 08:10

xomena


I experienced a similar issue periodically, when geocoding US zip-codes. Appending the country name after the zip-code seemed to fix the problem. So, instead of 60162 use 60162 USA.

like image 42
levi Avatar answered Oct 10 '22 07:10

levi