0

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?

4

4 回答 4

0

You can use optional parameter radius.

radius — The distance (in meters) within which to return Place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area. See Location Biasing.

于 2012-10-03T08:19:57.670 回答
0

The only way I can see to force this is to do the filtering yourself in the result array that you get when performing the search. I haven't used the Autocomplete API, but it seems you are using the Maps API to search? In that case, you get a GeocoderResult object which you can inspect the coordinates for the items, and compare them to your desired point and radius.

A bit hacky, but quite straightforward.

于 2012-10-03T12:21:38.327 回答
0

This example (uses the Google Maps API v3 places library):

http://www.geocodezip.com/v3_GoogleEx_place-search.html

from this answer:

Google places autocomplete - location and radius not working

uses rankby=distance

You can process the results to remove any not within your desired radius.

于 2012-10-03T13:37:04.287 回答
0

The location and radius parameters 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 the components parameter as detailed in the documentation.

If you use the location, radius and component parameters 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

于 2012-10-05T05:00:58.037 回答