Search code examples
javascriptgoogle-mapsmarkerclusterer

What does 'gridSize' define in MarkerClusterer under 'option' object?


I am working on Google Maps and clustering of markers using MarkerClusterer library. What exactly does 'gridSize' parameter define in 'option' object? If it is the size of a cluster image in pixels, then how can I change it for different clusters in the same map?

I have tried using the MarkerClusterer library using the documentation provided at this link: https://developers.google.com/maps/documentation/javascript/marker-clustering

It doesn't explain how to change and add 'option' object and how can we edit the option code according to our needs.

I would like you to help me with making the cluster image size different for different clusters on the same map.


Solution

  • The MarkerClusterer library's reference states:

    gridSize - The grid size of a cluster in pixels.

    To use this option you can either add it in your MarkerClusterer options upon object creation:

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

    Or use the setGridSize method:

    markerCluster.setGridSize(90);
    

    And to check the current grid size of your markerCluster use getGridSize.

    Hope this helps you.