Auto close InfoWindow in googlemap

会有一股神秘感。 提交于 2019-11-29 13:05:50
geocodezip

If you only want one infowindow ever, only create one InfoWindow (in the global scope), reuse it and change its contents when a marker is clicked, close it if the user clicks on the map.

similar question

 var iw = new google.maps.InfoWindow(); // single global infowindow
 google.maps.event.addListener(map, 'click', function() {
   iw.close();
 });
 function bindInfoWindow(marker, map, title, race, loc, org, web, link) {
   google.maps.event.addListener(marker, 'click', function() {
     iw.close();
     var html= "<div style='color:#000;background-color:#fff;padding:5px;width:250px;'><h4>"+title+"</h4><p>Race</p><h4>"+race+"</h4><p>Location</p><h4>"+loc+"</h4><hr /><p>Organizzazione</p><h4>"+org+"</h4><a href='"+link+"'' >"+web+"<a></div>";
     iw.setContent(html);
     iw.open(map,marker);
   });
}

working fiddle - different code as you didn't provide a complete example, demonstrates the concept.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!