ggirodda
ggirodda

Reputation: 790

Google maps api autocomplete - get location in one city (or few cities)

I already Googled that but I didn't find any answer. Is it possible to get in the Google Maps autoComplete results only locations in given cities? For example I want all the addresses in the city of Paris and New York, and exclude every other result. I didn't find this in the docs, I can filter results by country, but I want to filter by city. Is there any callback function that I can pass to the service that will be called for every result and exclude it from the list if my callback function return false?

Upvotes: 1

Views: 2602

Answers (2)

Preston
Preston

Reputation: 876

No, this is not currently possible, but there is long-standing feature request on the Public Issue Tracker to have the Places Autocomplete's componentRestrictions option be more similar to the same option for the Geocoding Service, as Autocomplete only supports countries (up to 5) while the geocoder allows for other component filters, including city/locality. You may want to star the issue to get updates and show increased interest in this being implemented.

Upvotes: 1

Omar
Omar

Reputation: 180

Well if you are looking to setup a region/location bias; you can bias the autocomplete results to favor an approximate location or area, in the following ways:

Set the bounds on creation of the Autocomplete object.
Change the bounds on an existing Autocomplete.
Set the bounds to the map's viewport.
Restrict the search to the bounds.
Restrict the search to a specific country.

See Docs for more information.

Upvotes: 2

Related Questions