Android Google Maps: disable dragging in MapFragment
Asked Answered
A

7

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!!

Almetaalmighty answered 7/6, 2013 at 8:30 Comment(0)
C
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).

Creighton answered 7/6, 2013 at 9:8 Comment(4)
Thanks! That's the great help!!Almetaalmighty
Link is broken.Sukkoth
Updated link: developers.google.com/maps/documentation/android-sdk/controlsNissy
Try this : https://mcmap.net/q/319760/-android-google-maps-disable-dragging-in-mapfragmentMasonmasonic
W
114

You can disable dragging in MapFragment using:

googleMap.getUiSettings().setScrollGesturesEnabled(false);
Welcy answered 23/12, 2014 at 9:22 Comment(0)
C
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).

Creighton answered 7/6, 2013 at 9:8 Comment(4)
Thanks! That's the great help!!Almetaalmighty
Link is broken.Sukkoth
Updated link: developers.google.com/maps/documentation/android-sdk/controlsNissy
Try this : https://mcmap.net/q/319760/-android-google-maps-disable-dragging-in-mapfragmentMasonmasonic
U
16

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);
Unhand answered 4/12, 2017 at 13:55 Comment(1)
second 1 about zoom, was usefull. +1Bipetalous
B
8

you can use isScrollGesturesEnabled for map

java:

googleMap.getUiSettings().setZoomGesturesEnabled(false);

kotlin

googleMap?.uiSettings?.isScrollGesturesEnabled = false
Bernat answered 17/9, 2018 at 5:42 Comment(0)
M
6

You can disable dragging in MapFragment using:

    mMap.getUiSettings().setScrollGesturesEnabled(false);
    mMap.getUiSettings().setZoomGesturesEnabled(false);
    mMap.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(false);
Masonmasonic answered 13/3, 2020 at 5:46 Comment(0)
E
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.

Embrasure answered 5/10, 2019 at 4:44 Comment(0)
D
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);
    }```
Dumortierite answered 19/10, 2022 at 0:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.