Disable pan/zoom in com.google.android.maps.MapView

只谈情不闲聊 提交于 2019-12-06 18:58:51

问题


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:


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




回答2:


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

map.getUiSettings().setScrollGesturesEnabled(false);



回答3:


This is gauranteed to work

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



回答4:


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




回答5:


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.




回答6:


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



回答7:


on your onMapReady method, add these code lines

gMap.getUiSettings().setZoomGesturesEnabled(false);

to disable all the guesures

gMap.getUiSettings().setAllGesturesEnabled(false);

happy coding :)



来源:https://stackoverflow.com/questions/3615816/disable-pan-zoom-in-com-google-android-maps-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!