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); 
Sign up to request clarification or add additional context in comments.

1 Comment

doesnt disable all gestures. Check my answer
15

This is gauranteed to work

mapView.getMap().getUiSettings().setAllGesturesEnabled(false); 

2 Comments

Note the question is from Maps API v1 era. This answer is for API v2.
@laalto Everyone who checks it now is on v2. Will help everyone who sees answers today
11

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

3 Comments

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
There still remains the issue of OnClickListener on a mapView
@Julius: MapView is closed source. There is nobody who will answer your onClickListener question.
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

Comments

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.

Comments

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); } 

Comments

0

on your onMapReady method, add these code lines

gMap.getUiSettings().setZoomGesturesEnabled(false); 

to disable all the guesures

gMap.getUiSettings().setAllGesturesEnabled(false); 

happy coding :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.