2010-07-09 74 views

回答

0

您可以在Javascript中使用typeof函数。

if (typeof(marker.infowindow) === "undefined"){ 
//object doesn't exist 
} 
else{ 
//the object does exist 
marker.infowindow.close(); 
} 
+0

我试过,但它似乎总是未定义。 – Federico 2012-01-12 21:36:08

0

您可以为您用作InfoWindow内容的div指定ID。 document.getElementById('content-div-id')将在InfoWindow在地图上打开时返回div,否则返回null

0

您可以使用一个变量来检查,如果一个信息窗口存在:

var currentInfoWindow = null; 

if(currentInfoWindow !== null){ 
    currentInfoWindow.close(); 
} 

然后,调用infoWindow.open()后currentInfoWindow分配给新的信息窗口:

currentInfoWindow = infoWindow; 

这是特别有用确保在地图上只打开一个infoWindow。

相关问题