【问题标题】:how to close a infowindow on googlemap如何关闭谷歌地图上的信息窗口
【发布时间】:2013-08-05 11:18:42
【问题描述】:

我正在尝试查找如何自动关闭或/和关闭标记的信息窗口(谷歌地图)。

我处理了那个代码,但我不明白为什么关闭函数没有关闭 de infowindow。我的 Firefox 控制台没有错误

这是代码,我们将不胜感激

//Infowindow
google.maps.event.addListener(markers[i], 'click', function() {

/* the marker's content gets attached to the info-window: */
var info = new google.maps.InfoWindow({
    content: this.content
});
info.close(); // IT DOES NOT CLOSE the open infowindow or all open

/* trigger the infobox's open function */
info.open(map,this); //This works

/* keep the handle, in order to close it on next click event */
//infos[0]=info;

});

非常感谢

【问题讨论】:

标签: google-maps google-maps-api-3 google-maps-markers infowindow


【解决方案1】:

当我添加 infowindow.close() 时,我有类似的代码似乎可以工作,也许你可以在我的找到答案:

google.maps.event.addListener(marker, 'click', (function(marker, content) {
        return function() {
            map.panTo(marker.position);
            infowindow.setContent(content);
            infowindow.open(map, marker);       
            map.circle.setCenter(marker.position);
            infowindow.close();
        }
    })(marker, content));

【讨论】:

    【解决方案2】:

    关闭信息窗口时需要传递两个参数。您可以尝试下面列出的功能。在单击事件上调用 close 方法以在打开标记上的新信息窗口之前关闭现有信息窗口。

    当您将鼠标从标记上移开时,此代码将删除信息窗口,并在您单击标记时打开信息窗口。

    试试这个并告诉我。

    var info = new google.maps.InfoWindow({
    content: this.content
    });
    
    google.maps.event.addListener(marker, 'click', function() { 
        info.close(map,marker); 
        info.open(map,marker); 
    });
    
    google.maps.event.addListener(marker, 'mouseout', function() {
         info.close(map,marker); 
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多