5

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

I've 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 obtain zip codes starting with 20, but it doesn't work. I have following responce from the server:

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

How can I make it works>

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
hipek
  • 201
  • 1
  • 3
  • 15

3 Answers3

3

The problem with your request is that postal_code is not a valid type to pass to the AutoComplete endpoint. If you look at place types for the AutoComplete endpoint you can see the four allowed types are geocode, establishment, (regions), and (cities). The closest you can get to what your looking for is setting the type to "types=(regions)".

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

  • locality
  • sublocality
  • postal_code
  • country
  • administrative_area1
  • administrative_area2
Bobbake4
  • 24,509
  • 9
  • 59
  • 94
  • 5
    Thanks, but do you have a working solution hot to retrieve only postal codes using AutoCompleteTextView and Google Places API? – hipek Jul 16 '13 at 13:53
0

You need to add two headers to request if you want to make this HTTP request (now you aren't using api) from an android device: An SHA-1 code, with an inclusion with header "x-android-cert" Your package name, with an inclusion with header "x-android-package"

Note that first you need to add this two params to credentials into your google console

As answered at this post Restricting usage for an Android key for a Google API

Ornitologo
  • 19
  • 6
0

use the following request with the google api place textsearch endpoint

https://maps.googleapis.com/maps/api/place/textsearch/json?query=971&fields=formatted_address&inputtype=textquery&key=[my_key]
micah
  • 838
  • 7
  • 21