10

Is there a way to disable the zooming (pinch and double tap) in the MapView but keep the scrolling?

This means setting clickable to false would not work.

I have also tried setting an onTouch listener in the activity but it will not trigger using:

mapView.setOnTouchListener(this);
Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
Klaasvaak
  • 5,634
  • 15
  • 45
  • 68

5 Answers5

27
import com.google.android.gms.maps.GoogleMap;

public void onMapReady(GoogleMap map) {
...
map.getUiSettings().setZoomGesturesEnabled(false);

UiSettings Documentation

JRichardsz
  • 14,356
  • 6
  • 59
  • 94
laalto
  • 150,114
  • 66
  • 286
  • 303
9

You can assign those properties using the XML file:

   map:uiRotateGestures="true"
   map:uiScrollGestures="true"
   map:uiTiltGestures="true"
   map:uiZoomGestures="true"

So use:

   map:uiZoomGestures="false"

On the MapFragment object.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • This solution did not work when adding the above code to my Map Fragment in the xml. @JRichardsz answer is correct. After implementing "map.getUiSettings().setZoomGesturesEnabled(false);" I successfully disabled zoom. – AdamHurwitz Jan 26 '18 at 00:06
4

here is example on Kotlin:

map.uiSettings.setAllGesturesEnabled(false)
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
Vladislav
  • 1,236
  • 13
  • 22
1

U may also try some thing like that ..

NOTE : this method disables zoom in / out functionality for Google map UI

Above two answer is correct as per question asked. Thanks David for updating me.

GoogleMap myMap;

myMap.getUiSettings().setZoomControlsEnabled(false);

For more public methods available for Google Map UI ..

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/UiSettings#setZoomControlsEnabled(boolean)

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
  • This does not disable pinch zoom and/or double tab zooming, it only disables the +/- zoom buttons that are displayed by default on a map. – dm78 Jul 12 '14 at 16:00
  • yup David .. It doesn't disables pinch property .. By mistake I mentioned this answer. My solution disables zooming option from UI. Answer mentioned above is correct. Also answer by laato is more precise. Thanks for updating me. Updating with new one. – AndroidHacker Jul 13 '14 at 06:35
0

If you're looking for a solution in Google Maps for Compose you can use this one:

GoogleMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState,
    uiSettings = MapUiSettings(
        scrollGesturesEnabled = false,
        zoomGesturesEnabled = false,
        zoomControlsEnabled = false
    )
)
rob
  • 2,136
  • 8
  • 29
  • 37