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. How would I do that with MarkerClusterer
?
JavaScript
x
24
24
1
function map(data, baseLat, baseLng){
2
var markers = [];
3
var map = new google.maps.Map(document.getElementById('map'), {
4
zoom: 10,
5
center: new google.maps.LatLng(baseLat, baseLng),
6
mapTypeId: google.maps.MapTypeId.ROADMAP
7
});
8
9
var infowindow = new google.maps.InfoWindow();
10
11
$.each(data, function(i, val) {
12
var marker = new google.maps.Marker({
13
position: new google.maps.LatLng(val.property.lat, val.property.lng),
14
//map: map,
15
title: "Title"
16
});
17
18
markers.push(marker);
19
20
});
21
22
new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
23
}
24
Advertisement
Answer
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
:
JavaScript
1
2
1
new MarkerClusterer(map, markers, {minimumClusterSize: 5, imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
2