How to keep single Info window open at the same time in Google map V3?

我是研究僧i 提交于 2019-11-29 16:35:03

Instead of multiple infoWindows use only one instance.

When clicking on a marker, first close the infoWindow, then set the new content and open the infoWindow.

function add_marker(lat,lng,title,box_html) 
{
  //create the global instance of infoWindow 
  if(!window.infowindow)
  {
    window.infowindow=new google.maps.InfoWindow();
  } 

  var marker = new google.maps.Marker({
      position: new google.maps.LatLng(lat,lng),
      map: map,
      title: title
  });

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

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