This is my code:
function addMarker(place)
{
var opts = {
position: {lat: parseFloat(place.latitude), lng: parseFloat(place.longitude)},
map: map,
title: place.place_name + ", " + place.admin_name1,
labelContent: place.place_name + ", " + place.admin_name1,
labelAnchor: new google.maps.Point(22, 0),
//labelClass: "labels",
labelStyle: {opacity: 0.75}
};
marker = new MarkerWithLabel(opts);
marker.addListener('click', function() {
var html = "<ul>";
$.getJSON("articles.php", "geo=" + place.place_name, function(data) {
if (data.length > 0)
{
$.each(data, function(key, value) {
html = html + "<li><a href= " + value.link + ">" + value.title + "</a></li>";
});
}
else html = "<li> No news today </li>";
html = html + "</ul>";
showInfo(marker, html);
});
//showInfo(this, html);
});
markers.push(marker);
}
What's wrong and what I've tried.
The problem is that using showInfo
the way is currently implemented, everything works except the info window appears on the wrong marker. I've read many answers and tried changing marker
to this
but then it throws me an error.
I've also tried using the showInfo
function a little below the current one (it's now commented) with the this
keyword and using it that way puts the info windows in the correct markers, but the info windows show empty.
I don't know what's wrong and I hope someone can help me find my error :)
var
keyword for my variable calledmarker
. Now everything works fine!