禁用 com.google.android.maps.MapView 中的平移/缩放

发布于 2024-09-17 00:48:46 字数 110 浏览 2 评论 0原文

如何禁用 MapView 的平移/缩放功能(不是缩放控件,我想要完全静态的地图)?

我还注意到触摸地图似乎不会触发 MapView onClickListener,有人可以详细说明为什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

苹果你个爱泡泡 2024-09-24 00:48:46

对于 Android 版 Google Maps API 版本 2,方法如下:

map.getUiSettings().setScrollGesturesEnabled(false);

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

map.getUiSettings().setScrollGesturesEnabled(false);
帥小哥 2024-09-24 00:48:46

这是保证工作的

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

This is gauranteed to work

mapView.getMap().getUiSettings().setAllGesturesEnabled(false);
勿忘初心 2024-09-24 00:48:46

在布局文件中使用 android:clickable="false"

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

月光色 2024-09-24 00:48:46

我有同样的问题,以下解决方案是我能找到的最好的解决方案,并且满足了我的要求:

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

正如 Alexander Stolz 在此发布的:

如何在 Android MapView 中禁用捏合

原因如下:

它不会完全禁用在 mapView 上的点击 - 它只会抓取和点击地图视图。防止使用两根手指手势(要进行缩放,您需要两根手指) - 点击地图(例如在叠加层上)仍然有效。

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.

萌酱 2024-09-24 00:48:46

这是正确的方法

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

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);
}
墨小沫ゞ 2024-09-24 00:48:46

在您的 onMapReady 方法中,添加这些代码行

gMap.getUiSettings().setZoomGesturesEnabled(false);

以禁用所有猜测

gMap.getUiSettings().setAllGesturesEnabled(false);

快乐编码:)

on your onMapReady method, add these code lines

gMap.getUiSettings().setZoomGesturesEnabled(false);

to disable all the guesures

gMap.getUiSettings().setAllGesturesEnabled(false);

happy coding :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文