Reputation: 46373
I've noticed that :
when writing some text in an <input>
field with Google Places Autocomplete API on my desktop computer, the propositions are made in my local area (Orleans, France),
when writing some text in an <input>
field with Google Places Autocomplete API on my mobile, the propositions are made in Paris, France, which is not where I am.
This is probably due to implicit IP geolocation.
How to force Google Places Autocomplete input field to "guess" the propositions in the area of a specified city? (in my case: Orleans, because my website is dedicated to users of this city)
Upvotes: 0
Views: 1172
Reputation: 5383
Try to read up on "Location Biasing" in the Google Places API docs. You can add location
and a radius
parameter to the request to return results mainly from desired area.
So your request might look something like this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=SEARCH_STRING&location=ORLEANS_LAT,ORLEANS_LNG&radius=RADIUS_IN_METERS&key=YOUR_API_KEY
If you use google.maps.places.Autocomplete
class, take a look at this section of Google Maps JS API v3 docs. There is a bounds
parameters which according to the docs:
The area in which to search for places. Results are biased towards, but not restricted to, places contained within these bounds.
It's also worth noting that in both API's there is a components
or componentRestrictions
parameter which allows you to restrict searches based on country. E.g.:
autocomplete.setComponentRestrictions({country:'fr'}) //to restrict results only to France.
More on that in the linked docs.
Upvotes: 2