Add bounds to map to avoid swiping outside a certain region

前端 未结 9 1159
抹茶落季
抹茶落季 2021-02-01 12:45

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:



        
9条回答
  •  悲&欢浪女
    2021-02-01 13:35

    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
        }
    });
    

提交回复
热议问题