2011年12月5日 星期一

Google Map InfoWindow 控制只顯示一個


" If you only want one info window to display at a time (as is the behavior on Google Maps), you need only create one info window, which you can reassign to different locations or markers upon map events (such as user clicks).
Therefore, you may simply want to create one InfoWindow object just after you initialize your map, and then handle the click event handler as follows:
google.maps.event.addListener(curMarker, 'click', function() {
   infowindow.setContent(contentString);
   infowindow.open(map, curMarker);
});
Then the InfoWindow should automatically close when you click on a new marker without having to call the close() method. "

也就是說, 只要變數名稱一樣就好, API 會自動關掉其他同名的 InfoWindow.

沒有留言:

張貼留言