I’ve got a problem with Google Autocomplete rest api.
I need to return predictions only for certain radius, but “radius” parameter doesn’t filter incorrect results. Currently I get results from another cities and even other countries.
How can i force google autocomplete to not include any results that out of requested radius?
The
locationandradiusparameters only act as a bias to the results, there is currently no way to restrict results to a specific radius. You can however restrict results to a specific country by passing thecomponentsparameter as detailed in the documentation.If you use the
location,radiusandcomponentparameters you will most likely get the desired results.An example search for Eiffel Tower, with a lat,lng location in Melbourne, Australia, radius 50km, and country restrict to Australia returns “Eiffel Tower Chocolate & Confectionery” as the real Eiffel tower is not within the radius or in the country that the request is restricted to:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Eiffel+Tower&location=-37.816836,144.963123&radius=50000&components=country:au&sensor=false&key=your_api_key