2010-07-09 73 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。

相關問題