如何只用两根手指在谷歌地图内移动? [英] How to move inside google maps only with two fingers?

查看:487
本文介绍了如何只用两根手指在谷歌地图内移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对移动用户存在一个大问题:

我有一个谷歌地图,它有 width:100%所以当用户滚动窗口,如果触摸屏幕内部的地图,滚动它将只为地图,而不是所有的窗口......(昨天我父亲在地图XD滚动3分钟) p>

滚动窗口可能触摸屏幕的边界,但非常非常非常清晰,并不是所有的用户都明白这一点。
我不想用 width 小于 100%的地图,所以我必须找到其他解决方案。 ..



只有当它与两个手指接触时,几乎在捏放大时才会使地图可拖动。



可以使用哪些Google地图事件?可能:

  google.maps.event.addListener(map,'dblclick',function(event){
this.setOptions({draggable:true});
});

但也许一开始点击地图我应该提醒(用地图中的div)用两个手指移动地图?



您怎么看?和代码是正确的?



非常感谢我的英语和奇怪的问题:D

解决方案

如果您使用API​​ v3.27或更高版本。初始化map只需添加属性 gestureHandling:'Cooperative'



像这样

  var map = new google.maps.Map(document.getElementById('map'),{
zoom:4,
center:myLatLng ,
gestureHandling:'cooperative'
});

更多信息在这里



或者,如果您想在创建地图后执行此操作,请执行

  map.setOptions({gestureHandling:'cooperative'}); 

更多信息在这里


I have a big problem for mobile users:

i have a google maps that has width: 100% and so when the user scroll the window if touch the screen "inside" the map, the scroll it will be only for map and not for all window... (yesterday my father for 3 minutes scrolled inside the map XD)

To scroll the window is possible touch the border of screen, but is very very scrict and not all users understand this. I dont'want a map with a width less of 100% so i must found other solution...

This is it will be make the map draggable only when it is touch with two fingers, almost when pinch to zoom...

but which google maps event i can to use ?

maybe:

    google.maps.event.addListener(map, 'dblclick', function(event){
      this.setOptions({draggable:true});
    });

but maybe at first click on map i should to alert (with a div in map) that is possible to move the map with two fingers ??

What do you think? and code is correct?

Thanks a lot and sorry for my english and for strange question :D

解决方案

If you are using API v3.27 or higher. While initializing map just add property gestureHandling: 'Cooperative'

like this

var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4,
          center: myLatLng,
          gestureHandling: 'cooperative'
        });

More Info Here

Or if you want to do this after creating the map, do

map.setOptions({gestureHandling: 'cooperative'});

More Info Here

这篇关于如何只用两根手指在谷歌地图内移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆