简体   繁体   中英

Google Maps in android app integration not dragging/moving smoothly

In my android app I am integrating google map to a bottomsheetfragment dynamically, it is getting loaded smoothly but when I am performing any operation like moving map with finger, dragging the marker its not working smoothly, I had to click many times to move it right or left and vertical movement is not happening, please help.

// this code is to load fragment inside bottom sheet dialog fragment
if (mapFragment == null) {
                mapFragment = SupportMapFragment.newInstance();
                mapFragment.getMapAsync(this);
            }
            FragmentTransaction transaction = activity
                    .getSupportFragmentManager()
                    .findFragmentByTag(BottomDialogCommon.TAG)
                    .getChildFragmentManager()
                    .beginTransaction();
            // R.id.map is a layout
            transaction.replace(R.id.map, mapFragment).commit();

 @Override
        public void onMapReady(GoogleMap googleMap) {
            //mMap = googleMap;

            // Add a marker in Sydney and move the camera
            LatLng sydney = new LatLng(26.47674, 80.334466);
            googleMap.addMarker(new MarkerOptions().position(sydney).draggable(true).title("Marker in Sydney"));
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
            googleMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );
            // Enable the zoom controls for the map
            googleMap.getUiSettings().setZoomControlsEnabled(true);
            googleMap.getUiSettings().setScrollGesturesEnabled(true);
            googleMap.getUiSettings().setZoomGesturesEnabled(true);...

This happens because by default the bottom sheet fragment is cancellable. Dragging the map causes the fragment to move. So, when showing the map, set dialog.isCancellable to false and add a custom cancel button.

This occurs when you have two or more movable elements nested inside each other. A simple fix is to add android:nestedScrollingEnabled="true" tag to the first movable element. In your case you want to add this inside your bottomsheetfragment that contains your MapFragment .

Check out my GitHub repo for the example below.

bottomsheetfragment.xml

bottomsheetDialog.java

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM