Search code examples
google-mapsautocompletegoogle-places-apigeocodinggoogle-geocoder

Autocomplete for locations (city & postcode) restricted by bounds (fully restricted)


I'm trying to implement an autocomplete feature for locations (city & postcode). The results have to be within specified bounds (the website has a strong regional focus).

I tried to implement it by using the Google Autocomplete Places API, but the componentRestrictions parameter only accepts country (which is too unspecific for Germany in this case).
The bias seems to work in a good way, but i still get larger cities from all around the country, which goes against the regional scope of the project.

The Geocoding API does offer the restriction, but it returns only one result for most of the cases (which is not very useful for an autocomplete feature).

Is there a possibility to achieve my goal within the Google APIs, or is there an alternative API which I should check out?


Solution

  • It looks like strict bounds has been implemented in Google APIs now. They are the only service I know of with this autocompletion feature in Germany. Here is the text of their comment on Issue 8606:

    Good news!

    The Place Autocomplete web service and the Autocomplete class in the JavaScript Places library now support restricting predictions to be strictly within specific bounds:

    https://developers.google.com/places/web-service/autocomplete#location_restrict https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete

    Please file new feature requests for the Android and iOS Places API SDKs if you are interested in using this feature in the SDKs.

    See also the new "Strict Bounds" checkbox in this example: Place Autocomplete Restricted to Multiple Countries https://google-developers.appspot.com/maps/documentation/javascript/examples/full/places-autocomplete

    Note: strictBounds is currently only available in the JavaScript Places library as an option for the Autocomplete class, but we will be adding it to the AutocompletionRequest (for the AutocompleteService) as well in the coming weeks.

    Full disclosure: I worked for SmartyStreets, an address validation and verification company.