如何在谷歌地图 api v3 中一次只显示一个信息窗口

Nik*_*van 0 google-maps google-maps-api-3 google-maps-markers

我们可以在谷歌地图中一次只显示一个信息窗口,并为多个标记显示多个信息窗口。

意思是,当我单击标记时隐藏/关闭其他信息窗口并仅显示当前标记信息窗口。

谢谢。

ARI*_*ANA 5

我解决的方法如下

var infoWindowsOpenCurrently;// A temporarily variable to save currently opened info window
google.maps.event.addListener(marker, 'click', function() {
  typeof infoWindowsOpenCurrently !== 'undefined' && infoWindowsOpenCurrently.close();//if variable is defined close
  infowindow.open(map, marker);
  infoWindowsOpenCurrently = infowindow;//set current info window to temporary variable
});
Run Code Online (Sandbox Code Playgroud)