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?

Juliusz
  • 1,300
  • 1
  • 13
  • 22
  • This solution may help you http://stackoverflow.com/questions/6439811/can-panning-zooming-be-disabled-in-an-android-mapview-while-allowing-users-to-cl/9405201#9405201 – Dwayne Feb 23 '12 at 00:09

7 Answers7

22

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

map.getUiSettings().setScrollGesturesEnabled(false);
Sveinung Kval Bakken
  • 3,715
  • 1
  • 24
  • 30
15

This is gauranteed to work

mapView.getMap().getUiSettings().setAllGesturesEnabled(false);
Taranfx
  • 10,361
  • 17
  • 77
  • 95
11

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 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 Sep 01 '10 at 11:49
  • There still remains the issue of OnClickListener on a mapView – Juliusz Sep 01 '10 at 11:56
  • @Julius: `MapView` is closed source. There is nobody who will answer your `onClickListener` question. – CommonsWare Sep 01 '10 at 12:12
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.

Community
  • 1
  • 1
AgentKnopf
  • 4,295
  • 7
  • 45
  • 81
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

ojas
  • 33
  • 4
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);
}
theWalker
  • 2,022
  • 2
  • 18
  • 27
0

on your onMapReady method, add these code lines

gMap.getUiSettings().setZoomGesturesEnabled(false);

to disable all the guesures

gMap.getUiSettings().setAllGesturesEnabled(false);

happy coding :)

Ashana.Jackol
  • 3,064
  • 28
  • 22