So I haven't moved on to the remove marker situation but provided the rest of your code works, I think I was able to solve your problem.
Using the information from:
https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple
I was able to construct this code which would always pop up a window with the information provided:
// Add marker for place to map
function addMarker(place)
{
// Sourced from:
// (https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple)
var myLatLng = new google.maps.LatLng(place["latitude"],
place["longitude"]);
var ontentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km
(208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a
href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: place["place_name"] +", "+ place["admin_name1"],
label: place["place_name"] +", "+ place["admin_name1"]
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
I then moved the marker to above the source since most of the other questions about this pset that I ran into seemed to have that as constant, to create the marker first then add the data.
Every time I tried to use getJSON in my program it would wipe all the markers off my map so I went searching for answers. I ran into your question and saw that some of my formatting and usage for JSON was off so I fixed it. At first it didn't work, but as I continued to search most people also had the Flask.url_for("articles") as the url, but I ran into this reddit post that used "/articles" for the url for getJSON and it seemed to work. So my final code ended up looking like:
function addMarker(place)
{
// Sourced from:
// (https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple)
// Set marker place
var myLatLng = new google.maps.LatLng(place["latitude"], place["longitude"]);
// Create 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"]
});
// Sourced from and solved:
// (https://cs50.stackexchange.com/questions/28726/cant-get-articles-on-my-marker-and-city-markers-are-persisting)
// (https://www.reddit.com/r/cs50/comments/8523js/struggling_a_lot_with_pset_8_specifically_getjson/)
$.getJSON(("/articles"), {geo: place.postal_code}, function(articles) {
if (!$.isEmptyObject(articles))
{
contentString= "<ul>";
for (var i = 0; i < articles.length; i++)
{
contentString+= "<li><a target='_NEW' href='" + articles[i].link + "'>" + articles[i].title + "</a></li>";
}
}
contentString+= "</ul>";
});
// Allow marker to be clicked
marker.addListener('click', function() {
// Pass info into info window
showInfo(marker, contentString);
});
// Source (How to add to an array):
// (https://www.w3schools.com/jsref/jsref_push.asp)
markers.push(marker);
}
It worked for me so it seems like the problem you were having was how the url was defined for the getJSON function. Now I don't know if there is an issue with how you call the marker listener or the infoWindow but I'm sure you will find out.