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 772 forks source link

Info Window not opening in correct location #48

Open thdoan opened 8 years ago

thdoan commented 8 years ago

When marker clusterer is enabled and an info window is dynamically populated using setContent(), the info window opens up in the upper left hand corner instead of being positioned near the marker:

$gmap.map = new google.maps.Map(document.getElementById('map'), {...});
$gmap.infoWindow = new google.maps.InfoWindow();
/* Push some markers to $gmap.markers */
$gmap.clusterer = new MarkerClusterer($gmap.map, $gmap.markers);
...
marker = $gmap.markers[0];
$gmap.infoWindow.setContent('Test');
$gmap.infoWindow.open($gmap.map, marker);

The interesting thing is, if I comment out setContent() then the info window shows up next to the marker. If I comment out new MarkerClusterer(), then the info window shows up correctly regardless.

thdoan commented 8 years ago

For now here is my workaround:

...
marker = $gmap.markers[0];
$gmap.info.setPosition(marker.getPosition());
$gmap.info.open($gmap.map);
mohanadkaleia commented 8 years ago

Great, thanks for sharing the solution .. it worked for me :+1:

Mojo90 commented 8 years ago

@thdoan great, thx for sharing. helped me also out at the moment :) 👌🏿

QueridaChin commented 6 years ago

I found that it was because the 'map' attribute of clusterer's markers[0] is null that when i open infowindow with markers[0]'s position it showed in the wrong position.so i rewrite this line 'this.markers[i].setMap(null);' to 'this.markers[i].setVisible(false);',then the infowindow shows in correct position

danimail49 commented 6 years ago

@QueridaChin Can you please write us in which file we should make the code update you advice us? and write us the file path?

Thanks, Daniel