Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps: disable dragging in MapFragment

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

like image 961
Mahe Avatar asked Jun 07 '13 08:06

Mahe


People also ask

How do I stop Google Maps from moving on Android?

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

How do I drag a marker on Google Maps Android?

Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.


6 Answers

You can disable dragging in MapFragment using:

googleMap.getUiSettings().setScrollGesturesEnabled(false);
like image 86
madhu527 Avatar answered Oct 05 '22 12:10

madhu527


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

like image 39
dumbfingers Avatar answered Oct 05 '22 11:10

dumbfingers


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);
like image 27
Mohammad Hadi Avatar answered Oct 05 '22 12:10

Mohammad Hadi


you can use isScrollGesturesEnabled for map

java:

googleMap.getUiSettings().setZoomGesturesEnabled(false);

kotlin

googleMap?.uiSettings?.isScrollGesturesEnabled = false
like image 21
Rasoul Miri Avatar answered Oct 05 '22 11:10

Rasoul Miri


You can disable dragging in MapFragment using:

    mMap.getUiSettings().setScrollGesturesEnabled(false);
    mMap.getUiSettings().setZoomGesturesEnabled(false);
    mMap.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(false);
like image 33
Mujahid Khan Avatar answered Oct 05 '22 13:10

Mujahid Khan


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.

like image 36
Antony Harfield Avatar answered Oct 05 '22 11:10

Antony Harfield