I have been working on addMarker()
from scripts.js
and was stuck at the second half of the prompt. My markers and labels are showing perfectly, however, the info windows are not popping up when I click on the markers. Any suggestion would be great, thanks in advance!
function addMarker(place)
{
// assign markers
var image = 'http://maps.google.com/mapfiles/ms/micons/ylw-pushpin.png';
// https://developers.google.com/maps/documentation/javascript/markers#simple_icons
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#MarkerLabel
var marker = new google.maps.Marker({
position: {lat: parseFloat(place.latitude), lng: parseFloat(place.longitude)},
map: map,
icon: image,
label: {
text: place.place_name + ', ' + place.admin_code1,
color: 'blue',
fontSize: '16px'
}
});
// append marker to markers in order to delete all markers all at once through removeMarkers()
markers += marker;
var parameters = {
geo: place.postal_code
};
$.getJSON(Flask.url_for("articles"), parameters)
.done(function(data, textStatuts, jqXHR) {
for (var i = 0; i < data.length; i++)
{
marker.addListener(map, "click", function() {
showInfo(marker, data[i]);
info.open(map, marker);
});
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
// log error to browser's console
console.log(errorThrown.toString());
showInfo([]);
});
}
My code looks like this now:
$.getJSON(Flask.url_for("articles"), parameters)
.done(function(data, textStatuts, jqXHR) {
// https://www.w3schools.com/js/js_loop_for.asp
var infowindow_content = "<ul>";
for (var i = 0; i < data.length; i++)
{
infowindow_content += "<li>" + "<a href='{data[i].link}'>" + data[i].title + "</a>" + "</li>";
}
infowindow_content += "</ul>";
marker.addListener("click", function() {
showInfo(marker, infowindow_content);
info.open(map, marker);
});
})
infowindow_content += "<li>" + "<a href='{data[i].link}'>" + data[i].title + "</a>" + "</li>";
andinfowindow_content += "</ul>";
Thank you very much!