Open and Close InfoWindow onclick

后端 未结 3 618
失恋的感觉
失恋的感觉 2021-01-26 11:00

Can anyone help me code inside my eventListener so that an infowindow will do the following: open if it\'s currently closed, and close if it\'s currently open.

I\'ve

3条回答
  •  感情败类
    2021-01-26 12:07

    var currentInfoWindow = null; 
    
    then on every marker click event I do something like this: 
    
    var infowindow = new google.maps.InfoWindow({ 
        content: "your content here" 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
        if (currentInfoWindow != null) { 
            currentInfoWindow.close(); 
        } 
        infowindow.open(map, marker); 
        currentInfoWindow = infowindow; 
    }); 
    

    Source : https://groups.google.com/forum/#!topic/google-maps-js-api-v3/cA2VRg4TO1k

提交回复
热议问题