I can't get my infowindow to show up a list of news and their links. I know that /articles?geo=[value'] will return a JSON but I can't loop through this JSON in InfoWindow.

My code for addMarker is:

function addMarker(place)
    // create latlng variable for markers
    var latlng = new google.maps.LatLng(place["latitude"], place["longitude"]);

    // initiate markers
    marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: place["place_name"],

    google.maps.event.addListener(marker, "click", function(){
        var div = "<div id='info'>";
        var event = "<li id = 'news'>"
        $.getJSON(Flask.url_for('articles'), "geo="+place["postal_code"])
        .done(function(data, textStatus, jqXHR) {
            for(var i = 0; i < data.length; i++){
                event += "<ul>" + data[i]["title"] + '</ul>' + "<ul>" +data[i]['link'] + "</ul>";
        event += "</li>";
        div += event;
        div += "</div>";
        info.open(map, this);

After inspect with chrome, I found out that my infowindow only have

  • which means the loop wasn't executed. How to fix this?

    2 Answers 2


    I fixed this by moving all of the code up to info.setContent(div) outside of the click listener.

    • Your answer is not perfectly clear since you have info.setContent(div); inside the click handler. Jan 9, 2018 at 0:33

    try to put info from the loop to console.log(variable) and then see what is returned in chrome console - i had similar problem and it turned out that data structure was a bit not as i expected.

    You must log in to answer this question.

    Not the answer you're looking for? Browse other questions tagged .