简体   繁体   English

如何在集群中的Google地图标记上创建click事件?

[英]How can I create a click event on a google map marker in a cluster?

I am working from Google's Marker Clustering guide . 我正在使用Google的标记集群指南

I just want to add a simple event to the markers inside a cluster. 我只想向集群内的标记添加一个简单的事件。

Unfotunately, I cannot use marker.addListener('click', ... because no marker variable is declared. 不幸的是,我无法使用marker.addListener('click', ...因为未声明任何marker变量。

Any idea how to add a click event to multiple markers using the same markup in the clustering guide? 知道如何在丛集指南中使用相同的标记将点击事件添加到多个标记吗?

Many thanks! 非常感谢!

As suggested in Integrate Google Maps MarkerClusterer with infowindow , a marker should be created with a click event: 将Google Maps MarkerClusterer与infowindow集成中所建议,应使用click事件创建一个标记:

var markers = locations.map(function(location, i) {
  var marker = new google.maps.Marker({
    position: location
  });
  google.maps.event.addListener(marker, 'click', function(evt) {
    //Add click event
  });
  return marker;
});

Here is the solution added to Google's Marker Clustering example: https://jsfiddle.net/9dmj3rkr/ 以下是添加到Google 标记集群示例中的解决方案: https : //jsfiddle.net/9dmj3rkr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM