javascript - 单击 map 关闭所有标记

标签 javascript google-maps-api-3

我有这样的代码,如果用户单击 map 的任何部分,所有信息窗口都应该关闭。但我不知道为什么它不起作用。

如何打开我的信息窗口:

 google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(content);
        infowindow.open(map, marker);
    });

点击 map 后我必须关闭所有内容:

google.maps.event.addListener(map, 'click', function() {

        infowindow.close(map, marker);
    });

编辑:很难找到解决方案。显示的大多数线程都与关闭图标(如果有一个打开)有关。

最佳答案

如果您的 map 上只有一个名为“marker”的标记,则这应该有效:

google.maps.event.addListener(map, 'click', function() {

    infowindow.close();
});

只要函数运行时“map”变量和“infowindow”变量都在作用域内。

关于javascript - 单击 map 关闭所有标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18543994/

相关文章:

javascript - 如何获取对 Kendo UI TabStrip 中当前选定选项卡的引用?

javascript - 在 Google Maps Places API 中更改默认文本 "Enter a Location"

javascript - initMap 不是一个函数 - map 不渲染。谷歌地图 API - JS

javascript - Google Geocoder - 将坐标添加到字段

html - 如何安全地使用 Google API key

javascript - 使用 TS 的 Angular2 中的安全性

javascript - Firefox 扩展 - 突出显示文本时调用函数

javascript - 邮政信箱正则表达式在包含单词 "box"的地址上失败

javascript - 组 JS 事件

javascript - 在Google Maps v3上加载多条路线