Mickey A.
Mickey A.

Reputation: 35

How to Update/Best Utilize LatLngBounds Dynamically for Places Autocomplete and Google Maps in Android

Does anyone have any recommendations on best practices for dynamically updating LatLngBounds values for use in the Google Places Autocomplete API in Android? It is specifically for use in the method: getAutocompletePredictions (https://developers.google.com/android/reference/com/google/android/gms/location/places/GeoDataApi)

Ideally I'm interested in seeing how users are setting this to account for user-specific LatLngBounds based on their last known locations. I'm having difficulties implementing this based on my instantiation of the Autocomplete Adapter in my onCreate function in my MapsActivity, but not calling getLastLocation until onConnected.

Please let me know if I am approaching this question in the wrong, inefficient way.

Thanks!

Upvotes: 0

Views: 528

Answers (1)

Mickey A.
Mickey A.

Reputation: 35

I figured out that this actually had a quite simple solution:

Put a setter method in the autocomplete adapter's class:

public void setBounds(LatLngBounds bounds) {
    mBounds = bounds;
}

with mBounds being a member variable of the class.

With that in place you simply use the setBounds method in your MapsActivity class whenever you have calculated whatever you want to set LatLngBounds to (which will likely be after connecting and getting the user's location).

Hope this helps someone!

Upvotes: 1

Related Questions