简体   繁体   English

Google Maps信息窗口open()平移至地图边缘

[英]Google maps info window open() panTo edge of map

i have these two lines 我有这两行

map.panTo(respectiveMarker.getPosition());//Center in map the respective marker
infoWindow.open(map, respectiveMarker);

When infoWindow.open is executed the map pans to the edge. 当执行infoWindow.open时,地图将平移到边缘。 If i remove this line the map pans to the marker as expected. 如果我删除这条线,地图将按预期平移到标记。

Any ideas? 有任何想法吗?

Since you're using the v3 API you could simply prevent the infoWindow from shifting the map with the disableAutoPan option. 由于您使用的是v3 API ,因此可以使用disableAutoPan选项简单地阻止infoWindow移动地图。

Complete example: 完整的例子:

<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps disableAutoPan Demo</title> 
   <script src="http://maps.google.com/maps/api/js?sensor=false" 
           type="text/javascript"></script> 
</head> 
<body> 

   <div id="map" style="width: 200px; height: 200px"></div> 

   <script type="text/javascript"> 

   var myLatlng = new google.maps.LatLng(37.44, -122.14);
   var myOptions = {
      zoom: 4,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   }

   var map = new google.maps.Map(document.getElementById("map"), myOptions);

   var infowindow = new google.maps.InfoWindow({
      content: 'Test',
      disableAutoPan: true
   });

   var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Test Marker'
   });

   google.maps.event.addListener(marker, 'click', function() {
     infowindow.open(map, marker);
   });

   </script> 
</body> 
</html>

Screenshot: 截图:

disableAutoPan

There is no equivalent to the disableAutoPan in the v2 API's GInfoWindowOptions , and I am not aware of any workarounds for this. v2 API的 GInfoWindowOptions没有等效于disableAutoPan GInfoWindowOptions ,而且我不知道有任何解决方法。

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

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