2010-08-23 171 views
0
new google.maps.event.addListener(marker, 'click', function() { 
    infowindow.close(map, marker); //the code is not working.. 
    infowindow.open(map, marker); 
}) 

回答

3

將所有信息窗口存儲在一個數組中。並使用以下功能關閉當前打開的窗口。

即:

var infoWindow = new google.maps.InfoWindow; 

infoWindowArray.push(infoWindow); 


function resetInfoWindow(){ 
    if(infoWindowArray){ 
     for(i in infoWindowArray){ 
      infoWindowArray[i].close(); 
     } 
    } 
} 

調用函數resetInfoWindow()這樣的:

google.maps.event.addListener(marker, 'click', function() { 
     resetInfoWindow(); 
     infoWindow.setContent(str1); 
     infoWindow.open(map, marker); 
    });