CasperSL CasperSL - 1 year ago 108
Javascript Question

Google Maps clustering if markers greater than 5

I'm trying to add clusters into google map and below code works charm, but i need to add clusters if there are more than 5 markers at same place. Can anyone please help out? Thanks!!

function map(data, baseLat, baseLng){
var markers = [];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(baseLat, baseLng),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

$.each(data, function(i, val) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(val.property.lat, val.property.lng),
//map: map,
title: "Title"
});

markers.push(marker);

});

new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}

Answer Source

From the MarkerClustererPlus documentation

minimumClusterSize number

The minimum number of markers needed in a cluster before the markers are hidden and a cluster marker appears. The default value is 2.

To set it to 5:

new MarkerClusterer(map, markers, {minimumClusterSize: 5, imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download