Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  181] [ 3]  / answers: 1 / hits: 17096  / 13 Years ago, thu, september 1, 2011, 12:00:00

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.



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?



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



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.



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.


More From » google-maps

 Answers
11

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);

});


EDIT: Updated in response to question edit.


[#90309] Wednesday, August 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleew

Total Points: 70
Total Questions: 87
Total Answers: 117

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;