我有一个脚本,它循环并且一次添加一个标记。
我试图让当前的标记有一个信息窗口,只有5个标记在一个地图上的时间(4个没有信息窗口和1与)
如何为每个标记添加一个 id,以便根据需要删除和关闭信息窗口。
这是我用来设置标记的函数:
function codeAddress(address, contentString) {
var infowindow = new google.maps.InfoWindow({
content: contentString
});
if (geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
infowindow.open(map,marker);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}