aI know that this one is repeated question,
I am using google map v3 on my Django web based applicaiton. Where i am using Markers, Infowindow and polyline
. Everything works fine, except the one when i click on a marker to show the content by Info window, the previous opened info window didn't closed.
I am posting the my map code(only the script part or which are the useful):
var marker = add_marker(flightPlanCoordinates[i][0], flightPlanCoordinates[i][1],"Event Detail",myHtml);
Here myHtml
is a variable which contains the Info window content. I didn't define the variable here. SO ignore it.
marker.setMap(map);
}
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinatesSet,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
function add_marker(lat,lng,title,box_html) {
var infowindow = new google.maps.InfoWindow({
content: box_html
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map,
title: title
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,this);
});
return marker;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…