I am using Places.GeoDataApi for Android and I get different search results depending on the location of the device performing the request. I need the results to be consistently located inside the bounds. I don't see where that could be setup in the getAutocompletePredictions request. Is there anything I am missing?
I get address/place autocomplete suggestions using the GoogleApiClient and Places API through:
Places.GeoDataApi.getAutocompletePredictions()
The method requires a GoogleApiClient object, a String to autocomplete, and a LatLngBounds object to limit the search range. This is what my usage looks like:
LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.build();
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, "Starbucks", bounds, null);
Version in use: com.google.android.gms:play-services-location:8.3.0
Documentation: https://developers.google.com/places/android/autocomplete
Good news. As of April 2018 Google added possibility to specify how to treat the bounds in autocomplete predictions. Now you can use the
getAutocompletePredictions()
method ofGeoDataClient
class withboundsMode
parameterpublic Task<AutocompletePredictionBufferResponse> getAutocompletePredictions (String query, LatLngBounds bounds, int boundsMode, AutocompleteFilter filter)
source: https://developers.google.com/android/reference/com/google/android/gms/location/places/GeoDataClient
You can modify your code to something similar to:
I hope this helps!
I got the same problem.
Unfortunately, there is no way to get places in specific bounds using Google Places API Android.
However, you can still use Nearby Search using Google Places API Web Service.
Documentation here : https://developers.google.com/places/web-service/search?hl=fr
You should then be able to set the bounds in parameters, and get the places inside the bounds from the JSON response, as explained in this answer : https://stackoverflow.com/a/32404701/5446285