请参阅以下屏幕截图。
我的代码是
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,当点击另一个链接时(所有链接都有相同的类)。如何解决。
答案 0 :(得分:0)
为什么不重新使用您已有的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居中并允许重复使用它而不是创建谁知道多少。
我还为您提供了密切的代码。