googlearchive / js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
https://googlemaps.github.io/js-marker-clusterer/docs/reference.html
Apache License 2.0
1.28k stars 775 forks source link

Cluster disappears when markers at the same position #86

Open omerts opened 8 years ago

omerts commented 8 years ago

If I have a couple markers at the same location, clicking on the cluster zooms in, and a second click makes the cluster disappear.

To reproduce, you can use the simple_example.html, and just change:

var markers = [];
for (var i = 0; i < 100; i++) {
  var dataPhoto = data.photos[i];
  var latLng = new google.maps.LatLng(dataPhoto.latitude,
      dataPhoto.longitude);
  var marker = new google.maps.Marker({
    position: latLng
  });
  markers.push(marker);
}

To:

var markers = [];
var dataPhoto = data.photos[0];
for (var i = 0; i < 100; i++) {
  var latLng = new google.maps.LatLng(dataPhoto.latitude,
      dataPhoto.longitude);
  var marker = new google.maps.Marker({
    position: latLng
  });
  markers.push(marker);
}

Result

Before click: image

After click: image

matteodanelli commented 7 years ago

I've same issues. It returns visible when you change zoom level since it is computed every time. In addition to this, however, the info window placed on the marker is not correct. It shows some information related to Google Map position, instead of the information that I am providing.

pcsantana commented 7 years ago

Having the same issue. Did you find any solution to this?

omerts commented 7 years ago

Not yet

pcsantana commented 7 years ago

Hi!

Are you using the "markerclusterer" or "markerclustererplus"? If is the first one, here there is a 1.0.1 version that seems work (I tested and it worked for me).

If is the (plus version), this seems to have the same issue, but here there is a workaround that worked for me.

I hope this helps!

renehennig commented 7 years ago

Just define a "maxZoom" for your Google Map and place the following Code before the "clusterclick" (function: ClusterIcon.prototype.triggerClusterClick) trigger:

if (markerClusterer.isZoomOnClick()) { if (markerClusterer.getMap().getZoom() === markerClusterer.getMap().maxZoom) { return; } }

stefansl commented 7 years ago

I had the same issue, when the markercluster option maxZoom was not set. Adding maxZoom worked for me without any other workarounds with version 1.0.1

Dahkon commented 6 years ago

The update didn't worked for me (the event object in triggerClusterClick as been deleted in the updated version and I need it...).

So if someone is looking for another solution with version 1.0, this worked for me :

google.maps.event.addListener(markerCluster, "clusterclick", function(cluster, e) {
                    setTimeout(function() { markerCluster.redraw(); }, 100);
                });
rakeshmishrait commented 6 years ago

we can use:- https://jawj.github.io/OverlappingMarkerSpiderfier/demo-1.html https://github.com/jawj/OverlappingMarkerSpiderfier

https://stackoverflow.com/questions/20471417/multi-markers-same-location-google-maps?rq=1

lolaswift commented 6 years ago

For those who use AGM. You can do it like this: <agm-marker-cluster [maxZoom]="15"

tcarterfrance commented 5 years ago

Hi I just added a small random offset to all my markers $scale = 10000; $delta_lat = (mt_rand (0,100) - 50)/$scale; $delta_long = (mt_rand (0,100) - 50)/$scale; $post_latitude = $lat + $delta_lat; $post_longitude = $long + $delta_long;

tunguyen9669 commented 5 years ago

https://github.com/jawj/OverlappingMarkerSpiderfier

hello guys, I seen your comment and I feel interesting. How I can do like this at ios swift?

jack-fdrv commented 5 years ago

Hi I just added a small random offset to all my markers $scale = 10000; $delta_lat = (mt_rand (0,100) - 50)/$scale; $delta_long = (mt_rand (0,100) - 50)/$scale; $post_latitude = $lat + $delta_lat; $post_longitude = $long + $delta_long;

Helpful!!

tyluudinh commented 5 years ago

Best solution: Random lat lng for same location. I tried and success