Google Maps V3 API地图无法正确居中

时间:2012-03-28 15:14:53

标签: google-maps google-maps-api-3

从今天起,我一直在遇到Google地图的问题,当我将一些IndoBox添加到地图中时,导致地图不居中。

我有几个InfoBox如下:

var labels = [ 
   new InfoBox({
        content: "Old Town (Stare Mesto)",
        position: new google.maps.LatLng(50.088979, 14.414921),
        boxStyle: {
                   border: "2px solid white",
                   textAlign: "center",
                   color: "white",
                   fontSize: "8pt",
                   fontWeight: "bold",
                   width: "200px",
                   height: "17px",
                   background: "black",
                   opacity: 0.5,
                   filter: "alpha(opacity=50)"
        }
   }),
   new InfoBox({
        content: "New Town (Nove mesto)",
        position: new google.maps.LatLng(50.084243, 14.424405),
        boxStyle: {
                   border: "2px solid white",
                   textAlign: "center",
                   color: "white",
                   fontSize: "8pt",
                   fontWeight: "bold",
                   width: "200px",
                   height: "17px",
                   background: "black",
                   opacity: 0.5,
                   filter: "alpha(opacity=50)"
        }
   })
];

如果我在地图上添加它们

for (var i in labels) {
    labels[i].open(map);
}

然后将地图视口移动到这些标签。即使我调用map.setCenter(someLatLngObject)中心也被卡在那些InfoBox上。

预期会出现这种情况吗?

1 个答案:

答案 0 :(得分:2)

您是否尝试过disableAutoPan选项?

 new InfoBox({
        disableAutoPan: true,
        content: "New Town (Nove mesto)",
        position: new google.maps.LatLng(50.084243, 14.424405),