2011-02-03 3 views
1

Google지도 API를 사용하는 임 3 번. 메신저이 기능 caling에 의해 마커를 추가 :Google지도에서 푸시 핀 정보 표시가 닫히지 않음

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

당신은 클릭 이벤트가 발생합니다 그래서 당신이 해결 알고하지 마십시오 예를

//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

를 사용하는 경우 배열에 정보창을 추적하고 programmaticaly을 닫을 필요하지만 방법은 내가 그랬어 그것은이었다

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"닫기 버튼이 작동하지 않습니다 ...

관련 문제