I am trying to find a way I can cluster nodes on a Google Map from a custom entity according to particular regions in a country. I have been using the Geocoder module to geocode addresses but I now want to group these addresses into regional clusters. I need a way I can implement Google Map clustering in Drupal 8.

If there is a way to do it programtically please do not hesitate to illustrate.


In order to cluster your map pins/node results, you'll need to write your own javascript function to call the Google Maps Clustering Library/initialize the map (since as of Feb 23, 2018, the GMap module has yet to be fully ported/available for D8).

Based on Google's Marker Clustering Documentation/Example, I'd recommend creating a custom module that includes:

  1. The Google Maps Marker Clusterer js library.
  2. Setting up a json endpoint/route for the location nodes/entities
  3. Custom module javascript that loads the nodes from the endpoint above and parses them (their latitude & longitude data) for the locations array in the init_map function.

Worth noting:
The Google Maps clustering library is grid-based, dividing the map into squares of a certain size.

If you want regions bounded by state/provincial borders, this library won't satisfy the zoomed out map with multiple regions; you'll need something more custom. In such a case, you can:

  1. add a taxonomy for the regions (with a custom set of geocoordinates for the center or political capital of each region)
  2. load a custom high level map with the regions defined/outlined with svg polygon paths and displaying custom cluster pins
  3. on each specific regional map utilize the grid-based clustering library
  • I am still figuring out how am going to implement this solution but it has been very helpful so i will mark it as the correct answer. – tendaitakas Feb 27 '18 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.