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:
Place the call within a runnable and post it to the views handler, like so:
mapFragment.getView().post(new Runnable() {
@Override
public void run() {
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), CAMERA_PADDING));
}
});
When the view has been laid out the runnable will execute and correctly position the map. The issue with ahmadalibalochs answer, is that you will see a flash of the globe before it correctly positions itself. Posting it to the view handler, resolves this issue.