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
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);
}