Search code examples
androidautocompletegoogle-places-apibounds

Google Places Api, Place auto-complete mBound Query


I am new to Google Place API, and I am going through Google reference Guide of place auto-complete

To get prediction for auto complete addresses or places there is a parameter which bounds the map for prediction.

PendingResult result =
    Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query,
        mBounds, mAutocompleteFilter);

I want to know what the most efficient way to do not bound the map so I can run prediction for any part of the world.

For example If I enter Sydney Australia I get predictions from Sydney and If I enter Paris France I get predictions from there!


Solution

  • You can pass in a bounds for the entire world, i.e. a LatLngBounds from (-90, -180) to (90, 180).

    Alternatively: just pass in a bounds around the devices location—because the bounds here is just a bias and not a limit. As https://developers.google.com/places/android/autocomplete says [emphasis mine]:

    A LatLngBounds object, biasing the results to a specific area specified by latitude and longitude bounds.

    So a bounds for Sydney, Australia will still allow the user to autocomplete "Paris, France" just fine!