1

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?

Omar
  • 180
  • 1
  • 15
ggirodda
  • 770
  • 7
  • 19
  • In my case I found a solution using the parameter strictbounds with an additional select for the city, each city has an associated bound wich is dynamically set at the selection. Anyway I leave @Preston answer as the correct one because this is just a workaround – ggirodda Mar 26 '18 at 23:53
  • 1
    Possible duplicate of [how to filter address according country and city in google maps autocomplete address api](https://stackoverflow.com/questions/42810524/how-to-filter-address-according-country-and-city-in-google-maps-autocomplete-add) – xomena Mar 28 '18 at 20:42

2 Answers2

2

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.

Omar
  • 180
  • 1
  • 15
  • Ok, thank you. And can I set multiple bounds ? For example a bound for each city ? – ggirodda Mar 26 '18 at 22:06
  • @Ciro, this solution only offers a results "bias" versus a restriction implemented by [`componentRestrictions`](https://developers.google.com/maps/documentation/javascript/places-autocomplete#set_search_area). As @[Preston](https://stackoverflow.com/users/6762789/preston) points out, you may only bias through AutoComplete requests and not restrict like you would when [`component filtering` through GeoCoding](https://developers.google.com/maps/documentation/javascript/geocoding#ComponentFiltering). – Omar Mar 26 '18 at 22:14
  • Ok I understand. Thank you. Do you know if there are others librairies that implements this feature ? I really like google maps api, but I really need this feature, so I think I will move elsewhere – ggirodda Mar 26 '18 at 22:26
  • Apparently the boolean parameter strictbounds is intended to restrict the area to the given bound, so it will do the job. I only need to put a select for the city, each city has his own bound that is automaticaly set at the selection – ggirodda Mar 26 '18 at 23:50
  • @Ciro, that’ll definitely work for setting the mapBounds.. but your response results configuration is limited to the current restrictions allowed by `componentFiltering` of the autoComplete service. Though you may be able to set your bounds as far as the map viewport goes, your results however, may only only be restricted by the current options available, I.e regionBias, or componentFiltering by country. – Omar Mar 27 '18 at 00:12
1

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.

Preston
  • 856
  • 5
  • 6
  • Ok, thank you. Do you know if there are others autocomplete librairies that implement this kind of feature? I need to use it pretty soon, I can't wait for google implement it – ggirodda Mar 26 '18 at 22:16