CasperSL CasperSL - 3 years ago 249
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(,,
//map: map,
title: "Title"



new MarkerClusterer(map, markers, {imagePath: ''});

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: ''});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download