2011-02-03 122 views
1

即时通讯使用谷歌地图api v3。 IM通过caling此功能添加标记:infowindows上的图钉不关闭谷歌地图

function createMarker(posn, title, html) { 
       var marker = new google.maps.Marker ({position:posn, title: title, draggable: false}); 
       var infowindow = new google.maps.InfoWindow({content: html}); 
       google.maps.event.addListener(marker, "click", function() { 
        infowindow.open(map,marker); 
       }); 
       return marker; 
      } 

它工作正常,唯一的问题是,当我点击一个图钉的窗口打开,但是当我点击另一个图钉信息窗口窗口不会关闭这两个信息窗口的第一个图钉可见。

回答

0

你需要保持在一个阵列跟踪你的信息窗口和programmaticaly关闭它们当点击事件触发所以使用例如

//define a global array 
infoWindows = new Array(); 

//..do your stuff 

function createMarker(posn, title, html) { 
     var marker = new google.maps.Marker ({position:posn, title: title, draggable: false}); 
     var infowindow = new google.maps.InfoWindow({content: html}); 
     //add this infowindow to an array 
     infoWindows.push(infowindow); 
     google.maps.event.addListener(marker, "click", function() { 
     //go through the array and close all open info windows 
     for (i=0;i<infoWindows.length;i++) { 
      infoWindows[i].setMap(null); 
     } 
     //open current info window 
     infowindow.open(map,marker); 
     }); 
     return marker; 
} 
0

不知道你解决了这个,但我的方式做它是:

function createMarker(posn, title, html) { 
       var marker = new google.maps.Marker ({position:posn, title: title, draggable: false}); 

       google.maps.event.addListener(marker, "click", function() { 
        infowindow.open(map,marker); 
       }); 
       infowindow = new google.maps.InfoWindow({content: html}); 
       return marker; 
      } 

这个工程,并点击另一个引脚时关闭窗户,但“X”关闭按钮不起作用...