繁体   English   中英

如何在Google Maps中关闭先前的infoWindow

[英]How to close previous infoWindow in Google Maps

请看下面的截图。

屏幕截图

我的代码是

function get(position, html, resultsMap){ 

    //alert(position);
     var getDirection = new google.maps.InfoWindow({
        content: '',
        position: position
    });
    getDirection.close();
     getDirection.setContent(html);  
       getDirection.open(resultsMap);  
    }  

函数调用为

get(position, html, resultsMap); 

除上述问题外,所有这些工作正常。 我想关闭以前的infoWindow并在单击另一个链接(所有链接具有相同的类)时仅显示新的Infowindow。如何修复。

为什么不只是将现有的infoWindow重复用于新位置?

HandleInfoWindow(self.places()[p], contentString, p);
map.setCenter(marker.location);


var HandleInfoWindow = function(place, content, index) {
      var position = {
        'lat': place.lat(),
        'lng': place.lng()
      };
      infoWindow.setContent(content);
      infoWindow.setPosition(position);
      infoWindow.open(map);
};
// Closes infoWindow
infoWindow.close();

是的,需要更多代码才能使所有这些正常工作,但是这些部分将使您的infoWindow居中并允许其重用,而不是创建谁知道多少。

我还为您提供了封闭代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM