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:
The answer that is marked correct is not a 100% correct. I think that can still fail in cases where the map never loads due to connectivity, or if the map gets updated so quickly that it never fully finishes loading. I have used the addOnGlobalLayoutListener.
ConstraintLayout mapLayout = (ConstraintLayout)findViewById(R.id.activityLayout);
mapLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
//Your map code
}
});