Download
												
					
				
					
	
		
	
		
								
							
		- Overview
- Documents
- Demos
						User Rating:  2.6/5 ( 2 votes) 
						
					Your Rating: 
					The library creates and manages per-zoom-level clusters for large amounts of markers. This is a V3 implementation of the V2 MarkerClusterer.
Usage
To use a marker clusterer, create a MarkerClusterer object. In the simplest case, just pass a map to it.
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
  'zoom': 13,
  'center': center,
  'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), options);
var mc = new MarkerClusterer(map);
You may also specify a number of options to fine-tune the marker manager's performance. These options are passed via a object.
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
  'zoom': 13,
  'center': center,
  'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), options);
var mcOptions = {gridSize: 50, maxZoom: 15};
var mc = new MarkerClusterer(map, [], mcOptions);
Once you create a marker cluster, you will want to add markers to it. MarkerClusterer supports adding markers using the addMarker() and addMarkers()method or by providing a array of markers to the constructor:
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
  'zoom': 13,
  'center': center,
  'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), options);
var mcOptions = {gridSize: 50, maxZoom: 15};
var markers = [...]; // Create the markers you want to add and collect them into a array.
var mc = new MarkerClusterer(map, markers, mcOptions);
A Simple MarkerClusterer Example:
This example will show 100 markers on map.
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
  'zoom': 13,
  'center': center,
  'mapTypeId': google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), options);
var markers = [];
for (var i = 0; i < 100; i++) {
  var latLng = new google.maps.LatLng(data.photos[i].latitude,
      data.photos[i].longitude);
  var marker = new google.maps.Marker({'position': latLng});
  markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
class MarkerClusterer
This class extends google.maps.OverlayView.
Constructor
| Constructor | Description | 
|---|---|
| MarkerClusterer(map:google.maps.Map, opt_markers:Array.<google.maps.Marker>, opt_options:Object) | A Marker Clusterer that clusters markers. | 
Methods
| Methods | Return Value | Description | 
|---|---|---|
| addMarker(marker:google.maps.Marker, opt_nodraw:boolean) | None | Adds a marker to the clusterer and redraws if needed. | 
| addMarkers(markers:Array.<google.maps.Marker>, opt_nodraw:boolean) | None | Add an array of markers to the clusterer. | 
| clearMarkers() | None | Clears all clusters and markers from the clusterer. | 
| getCalculator() | function(Array|number) | Get the calculator function. | 
| getExtendedBounds(bounds:google.maps.LatLngBounds) | google.maps.LatLngBounds | Extends a bounds object by the grid size. | 
| getGridSize() | number | Returns the size of the grid. | 
| getMap() | google.maps.Map | Returns the google map that the clusterer is associated with. | 
| getMarkers() | Array. | Returns the array of markers in the clusterer. | 
| getMaxZoom() | number | Gets the max zoom for the clusterer. | 
| getStyles() | Object | Gets the styles. | 
| getTotalClusters() | number | Returns the number of clusters in the clusterer. | 
| getTotalMarkers() | Array. | Returns the array of markers in the clusterer. | 
| isZoomOnClick() | boolean | Whether zoom on click is set. | 
| redraw() | None | Redraws the clusters. | 
| removeMarker(marker:google.maps.Marker) | boolean | Remove a marker from the cluster. | 
| resetViewport() | None | Clears all existing clusters and recreates them. | 
| setCalculator(calculator:function(Array|number)) | None | Set the calculator function. | 
| setGridSize(size:number) | None | Returns the size of the grid. | 
| setMap(map:google.maps.Map) | None | Sets the google map that the clusterer is associated with. | 
| setMaxZoom(maxZoom:number) | None | Sets the max zoom for the clusterer. | 
| setStyles(styles:Object) | None | Sets the styles. | 
 JS Tutorial
JS Tutorial
						 
		
 
 
				 
 
				