12

How can i disable the panning/zooming functionality of a MapView (not the zoom controls, i want a wholly static map)?

I've also noticed that touching the map doesn't seem to trigger the MapView onClickListener, could anyone elaborate why?

1

7 Answers 7

22

For version 2 of the Google Maps API for Android, this is the way:

map.getUiSettings().setScrollGesturesEnabled(false);
1
  • doesnt disable all gestures. Check my answer
    – Taranfx
    Commented Dec 24, 2013 at 6:20
15

This is gauranteed to work

mapView.getMap().getUiSettings().setAllGesturesEnabled(false);
2
  • Note the question is from Maps API v1 era. This answer is for API v2.
    – laalto
    Commented Dec 24, 2013 at 6:53
  • 2
    @laalto Everyone who checks it now is on v2. Will help everyone who sees answers today
    – Taranfx
    Commented Dec 24, 2013 at 7:02
11

Use android:clickable="false" in your layout file.

3
  • Oh, i see what's going on now, it seems my attemps to setOnClickListener on the mapView were causing the scrolling despite android:clickable="false" being set in the layout file
    – Juliusz
    Commented Sep 1, 2010 at 11:49
  • There still remains the issue of OnClickListener on a mapView
    – Juliusz
    Commented Sep 1, 2010 at 11:56
  • @Julius: MapView is closed source. There is nobody who will answer your onClickListener question. Commented Sep 1, 2010 at 12:12
1

Please use Overlay to get the tap event on the map

http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/Overlay.html

1

I had the same question and the following solution is the best one I could find and that fulfilled my requirements:

mapView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getPointerCount() > 1) {
                return true;
            }
            return false;
        }
    });

As posted by Alexander Stolz here:

How to disable pinch in Android MapView

And here is the reason:

It does not disable clicking on the mapView completely - it only grabs & prevents two-finger gestures (for zooming you need two fingers) - tapping on the map (for instance on Overlays) still works.

0

this is the right way

@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{   
    switch (ev.getAction()&MotionEvent.ACTION_MASK)
    {
        case (MotionEvent.ACTION_DOWN):
        {   
            // do what you want
            // you may scroll map where you want
            // don't use 'break', the same in case pointer events;

            //break;
            return true;
        }
    }
    // 'super' go to the mapView procedures and scroll map in own algorithm
    return super.dispatchTouchEvent(ev);
}
0

on your onMapReady method, add these code lines

gMap.getUiSettings().setZoomGesturesEnabled(false);

to disable all the guesures

gMap.getUiSettings().setAllGesturesEnabled(false);

happy coding :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.