如何在谷歌地图中绑定标记的触摸事件?

sim*_* xu 5 javascript html5 google-maps google-maps-api-3 touch-event

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

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

我想做的就像iOS的谷歌地图客户端一样

Bra*_*ith 17

我以与shreedhar相同的方式实现了触摸事件,但使用了"mousedown"事件.我发现在网络视图(即PhoneGap)中使用Google Maps API时,移动设备上未触发"点击",但通过点按手机或点击网络即可触发"mousedown"事件.

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

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

此外,确保只在页面上定义一个infowindow变量,并将其重新用于所有标记,因此我将infowindow定义为"全局"变量window.infowindow.


Shr*_*har 1

在此链接中您可以获得许多示例。 https://google-developers.appspot.com/maps/documentation/javascript/examples/

最近我在研究谷歌地图,下面是可以拖放标记的代码,它在移动网络浏览器中运行得很好。

gmap : function(lat,lng){
            var stockholm = new google.maps.LatLng(lat, lng);
            var parliament = new google.maps.LatLng(lat, lng);
            var marker;
            var map;
            function initialize() {
                var mapOptions = {
                    zoom: 13,
                    disableDefaultUI: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    center: stockholm
                };
                map = new google.maps.Map(document.getElementById("gmapDiv"),mapOptions);
                marker = new google.maps.Marker({
                    map:map,
                    draggable:true,
                    animation: google.maps.Animation.DROP,
                    position: parliament
                });
               var infowindow = new google.maps.InfoWindow({
                   content: 'content'
               });
                google.maps.event.addListener(marker, 'click', function(){
                  infowindow.open(marker.get('map'), marker);
                  });
            }
            initialize();
        }
Run Code Online (Sandbox Code Playgroud)