Google geocoding API returns ZERO_RESULTS for postal code

▼魔方 西西 提交于 2019-12-10 13:37:37

问题


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?


回答1:


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!




回答2:


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.




回答3:


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!



来源:https://stackoverflow.com/questions/50224355/google-geocoding-api-returns-zero-results-for-postal-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!