0

I can show markers on the map and open info window when clicked the markers. However, the info window cannot show the list of articles, instead it only shows a bulletpoint and "undefined". From the log in console, the

  • element is also "undefined".

    I guess my parameters may have something wrong. Any help is appreciated. Thanks in advance.

    Here is my code:

    function addMarker(place)
    {
        // get latitude and longitude from place
        var myLatLng = {lat:place.latitude, lng:place.longitude};
    
        // instantiate marker
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map
        });
    
        // get articles for place
        var parameters = {
            geo: place.postal_code
        };
        $.getJSON(Flask.url_for("articles"), parameters)
        .done(function(data, textStatus, jqXHR) {
            // use DOM manipulation to create list
            // create list element
            var ulist = document.createElement('ul');
    
            // build list of links to articles
            for(var i = 0; i < data.length; i++)
            {
                // create list item element
                var item = document.createElement('li');
    
                // create text node of article title
                var t = document.createTextNode(data[i].title);
    
                // append the text to item
                item.appendChild(t);
    
                // append item to list
                ulist.appendChild(item);
            }
    
            // create temporary parent node to get innerHTML string
            var tmp = document.createElement("div");
            tmp.appendChild(ulist);
    
            // console log for test
            console.log(tmp.innerHTML);
    
            // listen for clicks on marker
            google.maps.event.addListener(marker, 'click', function(){
                showInfo(marker, tmp.innerHTML);
            });
        })
    
        .fail(function(jqXHR, textStatus, errorThrown) {
    
            // log error to browser's console
            console.log(errorThrown.toString());
        });
    
        // remember marker
        markers.push(marker);
    }
    

    1 Answer 1

    1

    I incorporated this addMarker function into my app and it showed the list of articles in the info window (though the articles don't have "links"). So I "tweaked" articles; changed
    return jsonify(lookup(request.args.get("geo"))) to
    return jsonify([lookup(request.args.get("geo"))]).
    In other words, added another level of "list" with []. It gave the same result you are seeing.

    1
    • I just found out it was the problem in my "articles" function. I added articles = [lookup(geo)] I have removed its [] and added link for the articles in info window already. It works now. Thanks!
      – eddiewong
      Commented Mar 30, 2017 at 16:06

    You must log in to answer this question.

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