Android Google Maps: disable dragging in MapFragment

前端 未结 6 855
死守一世寂寞
死守一世寂寞 2020-12-29 17:52

Can I disable drag functionality when the user tries to drag the map with his fingers without disturbing the Zoom in and Zoom out?

Any one please suggest an idea

相关标签:
6条回答
  • 2020-12-29 18:13

    You can disable dragging in MapFragment using:

    googleMap.getUiSettings().setScrollGesturesEnabled(false);
    
    0 讨论(0)
  • 2020-12-29 18:20

    for disable dragging in MapFragment this code :

    googleMap.getUiSettings().setScrollGesturesEnabled(false);
    

    works as @tomrozb said. but it dosn't disable map zoom by touch on map. for that use this code beside above code:

    googleMap.getUiSettings().setZoomGesturesEnabled(false);
    
    0 讨论(0)
  • 2020-12-29 18:25

    you can use isScrollGesturesEnabled for map

    java:

    googleMap.getUiSettings().setZoomGesturesEnabled(false);

    kotlin

    googleMap?.uiSettings?.isScrollGesturesEnabled = false
    
    0 讨论(0)
  • 2020-12-29 18:27

    I think here's what you're looking for:

    Inside Google Maps Android v2

    Scroll (pan) gestures

    A user can scroll (pan) around the map by dragging the map with their finger. You can disable scrolling by calling UiSettings.setScrollGesturesEnabled(boolean).

    0 讨论(0)
  • 2020-12-29 18:27

    You don't have to set this in code. You can configure the gestures from XML:

    <fragment
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/mapFragment"
        map:uiScrollGestures="false" />
    

    As well as uiScrollGestures, you can set uiZoomGestures, uiTiltGestures, and uiRotateGestures.

    See XML Attributes documentation.

    0 讨论(0)
  • 2020-12-29 18:30

    You can disable dragging in MapFragment using:

        mMap.getUiSettings().setScrollGesturesEnabled(false);
        mMap.getUiSettings().setZoomGesturesEnabled(false);
        mMap.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(false);
    
    0 讨论(0)
提交回复
热议问题