简体   繁体   English

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

[英]How to close previous infoWindow in Google Maps

Please see following screenshot. 请看下面的截图。

屏幕截图

My code is 我的代码是

function get(position, html, resultsMap){ 

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

Function call is 函数调用为

get(position, html, resultsMap); 

All this working fine except above issue. 除上述问题外,所有这些工作正常。 I want to close previous infoWindow and display only new Infowindow, when click another link ( all links has same class).How to fix. 我想关闭以前的infoWindow并在单击另一个链接(所有链接具有相同的类)时仅显示新的Infowindow。如何修复。

Why not just reuse the infoWindow you already have for the new location? 为什么不只是将现有的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();

Yes there is alot more code needed to get this all to work, but these parts will center your infoWindow and allow the reuse of it rather than creating who knows how many. 是的,需要更多代码才能使所有这些正常工作,但是这些部分将使您的infoWindow居中并允许其重用,而不是创建谁知道多少。

I've included also close code for you. 我还为您提供了封闭代码。

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

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