开发者

Zoom_changed - Center

开发者 https://www.devze.com 2023-03-04 13:37 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号