简体   繁体   English

Zoom_changed-中心

[英]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 http://www.hostelbars.com/map_test_v3_1.html

I think the problem is that you do infoWindow.setCenter(infoWindow.getCenter()); 我认为问题是您要做infoWindow.setCenter(infoWindow.getCenter()); This will get the center of the infoWindow and not the marker . 这将获得infoWindow的中心,而不是marker Try doing something like this: 尝试做这样的事情:

infoWindow.setCenter(marker.getPosition());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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