My app shows a map and i want that users can\'t swipe over a certain region. So i\'m trying to add bounds but it makes the app to crash. Here is the working code:
This worked for me:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mMapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMapFragment.getView().getViewTreeObserver().addOnGlobalLayoutListener(this);
}
@Override
public void onGlobalLayout() {
mMapFragment.getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
//Only after onMapReady & onGlobalLayout newLatLngBounds will be available
initMapPosition(); //newLatLngBounds here
}