62

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 of doing this! Thanks for your Precious help!!

Mahe
  • 2,707
  • 13
  • 50
  • 69

7 Answers7

114

You can disable dragging in MapFragment using:

googleMap.getUiSettings().setScrollGesturesEnabled(false);
tomrozb
  • 25,773
  • 31
  • 101
  • 122
madhu527
  • 4,644
  • 1
  • 28
  • 29
99

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).

dumbfingers
  • 7,001
  • 5
  • 54
  • 80
15

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);
Mohad Hadi
  • 1,826
  • 3
  • 24
  • 39
8

you can use isScrollGesturesEnabled for map

java:

googleMap.getUiSettings().setZoomGesturesEnabled(false);

kotlin

googleMap?.uiSettings?.isScrollGesturesEnabled = false
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
6

You can disable dragging in MapFragment using:

    mMap.getUiSettings().setScrollGesturesEnabled(false);
    mMap.getUiSettings().setZoomGesturesEnabled(false);
    mMap.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(false);
Mujahid Khan
  • 1,712
  • 1
  • 18
  • 24
2

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.

Antony Harfield
  • 850
  • 1
  • 7
  • 16
0

Can be achieved inside the onMapReady class:

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        //Hide zoom controls or buttons
        mMap.getUiSettings().setZoomControlsEnabled(false);
        //Restrict zoom gestures
        mMap.getUiSettings().setZoomGesturesEnabled(false);
    }```