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

125
March 27, 2018, at 07:28 AM

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?

Answer 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.

Answer 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.

READ ALSO
Slick.js: How to write for loop with an array?

Slick.js: How to write for loop with an array?

I'm trying to implement slide numbers for each of my galleries using slickjs

107
Javascript calling the same function multiple times and only alerting on the last function call

Javascript calling the same function multiple times and only alerting on the last function call

I have a function that calls a callback several times in a row on button click eventIn my callback it sends an alert to the user if the condition is met (bool is false)

77
How to add Bearer Token in get request with location.href?

How to add Bearer Token in get request with location.href?

Currently I have all ajax request that send Authentication token, but I created a service to export to excel, ajax doesn't support that and I am using locationhref for the get request

107
html2pdf colgroup background-color not working

html2pdf colgroup background-color not working

I am currently using html2pdf and saving a table to PDF by class name

70