Google Place API - autocomplete - how to get a zip code?

How can I get the autocomplete function from the Google Place API to complete a textView with zip codes?

I tried using this link:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=20&types=postal_code&language=de&sensor=false&key=myKey 

to get zip codes starting with 20, but that won't work. I have a response from the server:

 { "predictions" : [], "status" : "INVALID_REQUEST" } 

How can I make it work>

+4
source share
1 answer

The problem with your request is that postal_code is not a valid type to pass to the autocomplete endpoint. If you look at putting types for an autocomplete endpoint, you can see that the four allowed types are geocode, creation, (regions) and (cities). The closest thing you can do is get your search to set the type to "types = (regions)".

This will return any result that has one or more of the following types:

  • location
  • sublocality
  • postal_code
  • Country
  • administrative_area1
  • administrative_area2
+2
source

Source: https://habr.com/ru/post/1491521/


All Articles