简体   繁体   中英

Zoom_changed - Center

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.addListener(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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM