Question

I have implemented Google Places API with autocomplete and Google Geocoding Api. The problem is that it seems that the results do not work correctly.

Sometimes some of the choosen results from the autocomplete list do not geocode at all, all i get is the status ZERO_RESULTS.

I know that there could be some problems regarding the fact that Google Autocomplete uses also Places, while Google Geocode uses only postal codes, but how could i limit autocomplete to give me only postal codes results.

Was it helpful?

Solution

Place Types

You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types. The supported types are:

geocode

instructs the Place Autocomplete service to return only geocoding (address) results. Generally, you use this request to disambiguate results where the location specified may be indeterminate.

establishment instructs the Place Autocomplete service to return only business results. the (regions) type collection instructs the Places service to return any result matching the following types:

  • locality
  • sublocality
  • postal_code
  • country
  • administrative_area1
  • administrative_area2
  • the (cities) type collection instructs the Places service to return results that match either locality or administrative_area3.

    Hope this helps https://developers.google.com/places/documentation/autocomplete

    OTHER TIPS

    There is no way to achieve it via an Autocomplete.

    When you type in a autocomplete the API first will request the predictions, but not the details.

    This means that at the time when you see the predictions it's still not clear if there are details available for this place.

    There are cases when the particular place can't be found. I'm sure when it would be possible for google to exclude the missing places they wouldn't return them at all.

    The only workaround I see would be to create the autocomplete on your own by requesting both, predictions and details , before you apply the predictions. But note: each time the user types into the input this will count as 6 requests(assuming 5 predictions will be returned)

    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top