gpt4 book ai didi

javascript - 如何关闭 map 上标记的所有信息窗口

转载 作者:行者123 更新时间:2023-12-03 16:48:59 26 4
gpt4 key购买 nike

我用这些代码在我的 map 上添加了 3 个标记。但是当我点击它们时。信息窗口打开但其他标记信息窗口未关闭

function AddMarker(location, map) {
var contentString = '<div content="text/html; charset=windows-1254" style="font-family:Tahoma; font-size: 8pt; border:solid 0px black; width: 250px;" id="bodyContent">' +
'<p><b>Message Number: 12 </b> ' +
'</div>';

var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: location,
map: map,
title: 'Bilgi'
});
marker.addListener('click', function () {
infowindow.open(map, marker);
});
}

最佳答案

var activeInfoWindow;    
function AddMarker(location, map) {
var contentString = '<div content="text/html; charset=windows-1254" style="font-family:Tahoma; font-size: 8pt; border:solid 0px black; width: 250px;" id="bodyContent">' +
'<p><b>Message Number: 12 </b> ' +
'</div>';

var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: location,
map: map,
title: 'Bilgi'
});
marker.addListener('click', function () {
if (activeInfoWindow) { activeInfoWindow.close();}
infowindow.open(map, marker);
activeInfoWindow = infowindow;
});
}

关于javascript - 如何关闭 map 上标记的所有信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35428563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com