apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Clusterer doesn't work for markers with the same coordinates? #480

Closed ben-gy closed 9 years ago

ben-gy commented 9 years ago

Hey there,

gmaps4rails is great by the way - big thanks to everyone for their time committed to the project.

My issue - I've installed gmaps4rails and everything is working well, except for clustering for markers that share the same coordinates.

screen shot 2015-05-11 at 1 07 12 am

screen shot 2015-05-11 at 1 07 23 am

screen shot 2015-05-11 at 1 06 23 am

Here's my code for generating the markers and map:

<script type="text/javascript">
  window.setTimeout(function(){
    var handler;
    handler = Gmaps.build('Google', { markers: { maxRandomDistance: 5, do_clustering: true, clusterer_maxZoom: 20, clusterer_gridSize: 4, randomize: true } });
    handler.buildMap({
      provider: {
        disableDefaultUI: true,
        scrollwheel: false,
        zoomControl: true,
        streetViewControl: true,
        backgroundColor: '#B3D1FF'
      },
      internal: {
        id: 'map'
      }
    }, function() {
      var markers;
      markers = handler.addMarkers(<%=raw @marker.to_json %>); 
      handler.bounds.extendWith(markers);
      handler.map.centerOn({
        lat: -25,
        lng: 135
      });
      handler.getMap().setZoom(4);
    }, 200);
  });
</script>

Thanks in advance for your help :)

apneadiving commented 9 years ago

sorry, I'm not sure what you expect :)

apneadiving commented 9 years ago

btw, please provide the generated script if you'd like me to debug

ben-gy commented 9 years ago

Hey mate - thanks for the speedy response :)

I was expecting the clusterer to continue clustering at high zoom levels. Couldn't get that working, but I ended up passing parameters like this and it worked the way I wanted it to:

Gmaps.build('Google', { markers: { randomize: true, maxRandomDistance: 10, clusterer: { maxZoom: 20, gridSize: 40 }}});

Thanks anyway - hopefully this helps anyone who runs into the same problem.