我如何为谷歌地图中的标记绑定触摸事件? [英] how can i bind touch events for a marker in google maps?

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

问题描述

google maps 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的谷歌地图客户端一样

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

推荐答案

我实现触摸事件的方式与 shreedhar 相同,但使用的是mousedown"事件.我发现在 Web 视图(即 PhoneGap)中使用 Google Maps API 时不会在移动设备上触发点击",但鼠标按下"事件是通过点击移动设备或点击网络触发的.

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天全站免登陆