I am having trouble with addMarker in pset8. The markers are only shown one by one each time I pan or zoom in/out the view. And after 10 moves it keeps adding markers (limitation to 10 isn't working). Also when I click the marker it doesn't open the infoWindow. Can someone please help me? I have no clue what is wrong.
function addMarker(place) {
// extract the place latitude and longitude
var myLatLng = new google.maps.LatLng(place["latitude"], place["longitude"]);
// instantiate marker
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: place["place_name"] +", "+ place["admin_name1"],
label: place["place_name"] +", "+ place["admin_name1"],
});
// get articles for place
$.getJSON(Flask.url_for("articles"), {geo: place.postal_code}, function(articles) {
// Only display infowindow if articles exist
if (!$.isEmptyObject(articles))
{
// start Unordered List
var articlesContent = "<ul>";
for (var i = 0; i < articles.length; i++)
{
//Each list item is stored into articlesString
articlesContent += "<li><a target='_NEW' href='" + articles[i].link
+ "'>" + articles[i].title + "</a></li>";
}
}
// close the unordered list of articles
articlesContent += "</ul>";
// listen for clicks on marker
google.maps.event.addListener(marker, 'click', function() {
showInfo(marker, articlesContent);
});
});
// add marker to the map markers
markers.push(marker);
}