I've been stuck on this for a while and therefore simplified my requirement. When you click on a marker an infowindow opens, when a user zooms I want that marker to be in the center of the map. This doesn't work but I think it's close:
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addL开发者_运维百科istener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
google.maps.event.addListener(map, 'zoom_changed', function() {
infoWindow.setCenter(infoWindow.getCenter());
});
}
http://www.hostelbars.com/map_test_v3_1.html
I think the problem is that you do infoWindow.setCenter(infoWindow.getCenter());
This will get the center of the infoWindow
and not the marker
. Try doing something like this:
infoWindow.setCenter(marker.getPosition());
精彩评论