如何在Google Maps API v3的标记群集对象中的各个群集中找到标记? [英] how to find the markers in the individual clusters in a marker cluster object in google maps api v3?

查看:48
本文介绍了如何在Google Maps API v3的标记群集对象中的各个群集中找到标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此处的教程在任意缩放级别向标记集的各个群集添加了一个inforwindow. http://krisarnold.com/2010/10/15/adding-info-windows-to-map-clusters-with-google-maps-api-v3/

I followed the tutorial here to add an inforwindow to the individual clusters of markercluster at any zoom level. http://krisarnold.com/2010/10/15/adding-info-windows-to-map-clusters-with-google-maps-api-v3/

我想将各个集群中包含的标记信息(例如,当单击标记集群对象时,将其标题"添加到信息窗口中显示的列表中.)

I want to add the info of the markers (e.g. their 'title' s to a list displayed in the info window when clicked on the markercluster object.) contained in respective cluster.

因此,如果我在一个特定的缩放级别上有3个群集,则每个群集内部都有5个标记.如何显示特定集群中聚集的5个标记(markercluster对象中总共15个标记)的标题列表?

So if I have 3 clusters at a particular zoom level in view, each having 5 markers insider it. How do I display a list of the titles of the 5 (out of total 15 markers in markercluster object) markers aggregated in that particular cluster?

例如我在集群中有3个标记那我该如何在信息窗口中显示呢?titlemarker1titlemarker2titlemarker3

for e.g. I have 3 markers inside a cluster then how do I show this in the info window? titlemarker1 titlemarker2 titlemarker3

修改:如这里所见 http://www.blogwave.de/wp-content/uploads/2009/05/marker_cluster.png 所有不同的群集都是一个markercluster对象的实例.因此,如果我们使用下面的答案之一中提到的markercluster对象的getmarkers例程,那么我们将获得所有标记的列表.

edit: as seen here http://www.blogwave.de/wp-content/uploads/2009/05/marker_cluster.png all the different clusters are an instance of one markercluster object. So if we use the getmarkers routine of markercluster object as mentioned in one of the answers below then we get list of all markers.

我想要的例如从左起第一个从集群中标记为18的标记总数中仅获得这18个标记的列表.

What I want is for e.g. to get a list of only those 18 markers from the total markers in the cluster marked with 18, first from left.

推荐答案

不幸的是,MarkerClusterer引用很少.浏览源代码后,它看起来像您需要调用传入的 cluster 对象的 getMarkers 方法(与我之前建议的相反,该方法是在 markerClusterer上调用该方法).

Unfortunately, the MarkerClusterer reference is a bit scant. After browsing through the source code, it looks like you need to call the getMarkers method of the cluster object passed in (contrary to what I had previously suggested, which was to call the method on the markerClusterer).

例如,使用您链接到的教程:

For example, using the tutorial you've linked to:

google.maps.event.addListener(markerClusterer, 'clusterclick', function(cluster) {
    var content = '';

    // Convert lat/long from cluster object to a usable MVCObject
    var info = new google.maps.MVCObject;
    info.set('position', cluster.center_);

    //----
    //Get markers
    var markers = cluster.getMarkers();

    var titles = "";
    //Get all the titles
    for(var i = 0; i < markers.length; i++) {
        titles += markers[i].getTitle() + "\n";
    }
    //----


    var infowindow = new google.maps.InfoWindow();
    infowindow.close();
    infowindow.setContent(titles); //set infowindow content to titles
    infowindow.open(map, info);

});

编辑:已更新,以响应问题编辑.

Updated in response to question edit.

这篇关于如何在Google Maps API v3的标记群集对象中的各个群集中找到标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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