Add bounds to map to avoid swiping outside a certain region

前端 未结 9 1287
抹茶落季
抹茶落季 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:16

    Caused by: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
    

    The reason Behind this error is because the Map layout has not been completed, You should implement OnMapReadyCallback in your calls, which will ensure that your code will only run after your layout is completed or Implement the below callback

    map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition arg0) {
        map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30));
    }
    });
    

    Duplicate Links

    moveCamera with CameraUpdateFactory.newLatLngBounds crashes

    IllegalStateException map size should not be 0

    I don't if there is a way to merge this link. I Hope i helped

提交回复
热议问题