I have several thousand markers stored in a kmz file that I load into a Google Maps (v3 API).
I've looked around to find a way to cluster the overlay data, but to no avail.
MarkerClusterer looks nice, but it only seems to work with a marker array?
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(25,-20);
var myOptions = {
zoom: 2,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var ctaLayer = new google.maps.KmlLayer('thedata.kmz');
ctaLayer.setMap(map);
//cluster
var mcOptions = {gridSize: 50, maxZoom: 15};
var mc = new MarkerClusterer(map, ctaLayer, mcOptions);
}
How can I cluster the markers in the overlay, just like markerclusterer does it?
Best Answer
The KML file is actually read by a Google server, then served to the map as image tiles. Thus, you don't have access to the actual point objects. If you want to do clustering, you would have to load the KML another way and parse the points into an array, and then you can use whatever client-side clustering you want.
From the Google Maps V3 API docs: