我怎样才能绑定触摸事件的标记在谷歌地图? [英] how can i bind touch events for a marker in google maps?

查看:116
本文介绍了我怎样才能绑定触摸事件的标记在谷歌地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌地图API不支持触摸事件

google maps api does not support touch events

但现在我需要在地图和标记上做一些事情,比如长时间点击地图,点击标记,拖动标记。

but now i need to do some thing on the map and marker, such as long tap the map, tap the marker,drag the marker.

我想要做的事情与iOS的Google地图客户端相同

what i wanna do is the same as the google maps client for iOS

推荐答案

我以与shreedhar相同的方式实现触摸事件,但使用mousedown事件。我发现在网络视图(即PhoneGap)中使用Google Maps API时,移动设备不会触发点击,但是通过点按移动设备或点击网络触发mousedown事件。 / p>

I implemented touch events the same way as shreedhar, but using the "mousedown" event. I've found that "click" isn't triggered on mobile devices when using the Google Maps API in a webview (i.e. PhoneGap), but the "mousedown" event is triggered by a tap on mobile or a click on the web.

window.infowindow = new google.maps.InfoWindow({
   content: 'content'
});

google.maps.event.addListener(marker, 'mousedown', function(){
   window.infowindow.open(marker.get('map'), marker);
});

另外,请确保只在页面上定义一个infowindow变量,然后重新使用它的标记,因此为什么我将infowindow定义为全局变量window.infowindow。

Also, be sure to only define one infowindow variable on your page, and re-use it for all of your markers, hence why I defined infowindow as a "global" variable window.infowindow.

这篇关于我怎样才能绑定触摸事件的标记在谷歌地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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