Google geocoding API returns ZERO_RESULTS for postal code
Asked Answered
C

3

7

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?

Centra answered 8/5, 2018 at 0:58 Comment(2)
No, the request is correct. For instance, it works with maps.googleapis.com/maps/api/geocode/…, but for some strange reason it yields "ZERO_RESULTS" for 2010Ardolino
I have same experiences, for country:ch|postal_code:3001 - wheras 2575 for example, always works. 3001 works too, occassionaly! What where your findings on this issue?Carbonari
M
7

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!

Metrology answered 14/7, 2018 at 22:31 Comment(0)
P
4

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.

Plicate answered 14/7, 2018 at 19:35 Comment(3)
Its worth noting that the bug reported above is for 4 digit post codes so USA codes are not affected by this issue.Illuse
I have experienced this issue with certain ZIP codes, such as 60006 which happens to also be Illinois like 60162. Following @Plicate 's suggestion, appending with "USA" like 60006 USA has solved the problem.Epicritic
Thanks for this! DC zip code (20414) doesn't work, but appending "USA" gets results.Soulful
A
0

When a URL is opened in the browser based on its IP context, it identifies the country and automatically deduces the query format for a zip code is 99.999-99.

The format above is for Brazil, but there are different standards for each country such as USA and Portugal.

One solution when calling an API via CURL, either by code or by terminal, include the "&components = country: US" parameter, changing the "US" country code to what you want to filter.

The Google API returns ZERO_RESULTS for safety, because a search would be too slow and could do a global search worldwide and not just the country. For performance and speed reasons, Google creates this automatic ID for help, but unfortunately is not provided to developers about this process.

Good luck!

enter image description here

Ailina answered 23/10, 2019 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.