Skip to content
Advertisement

Map markers not clustering

I have a map which has multiple markers within close proximity of each other. Trying to integrate the marker clustering through google dev kit.

However the clustering is not occuring, and am also not getting an error in console – which makes it somewhat tricky.

Map data being used:

JavaScript

Javascript:

JavaScript

Which is displaying the map in html via the div ID ‘map’.

I have created a JSFiddle to see the map markers being loaded in #map, but as you can see. The markers are loading, but not clustering.

In a desperate attempt to resolve, have also tried changing the default zoom level, as I thought this might be creating the issue.

Link: https://jsfiddle.net/pixelmedia/z1ke9bwq/37/

Advertisement

Answer

Strange that no body reply you with the bounty.

Here is the clustered markers version based on yours:

https://jsfiddle.net/qakbnx6h/1/

The problem is in the addMarker(), for each place, you created a new MarkerClusterer so the clustering is not working.

To solve it:

  1. Remove new MarkerClusterer on addMark()
  2. return the marker from addMaker()
JavaScript
  1. Push the new marker into a array
  2. Add the new MarkerClusterer below $.each of places and use the array marker created on step 3
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement