googlearchive/js-marker-clusterer

Cluster disappears when markers at the same position

omerts opened this issue ยท 13 comments

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

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.

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

Not yet

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!

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; } }

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

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);
				});

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

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;

https://github.com/jawj/OverlappingMarkerSpiderfier

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

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!!

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