I don't know what is the problem in this code. When I click on a marker, it opens exact news on that location in an info window. But when I click on some other marker, it displays the info window on the previous clicked marker displaying news on the current clicked window. To say precisely, info window just reloads for the clicked marker but on same location. Please help me with this. I have been struggling for a week with this function. :(
function addMarker(place)
{
var image="http://maps.google.com/mapfiles/kml/pal2/icon31.png";
marker = new MarkerWithLabel({
position: new google.maps.LatLng(place.latitude,place.longitude),
map: map,
icon: image,
labelContent: place.place_name+","+place.admin_name1,
labelClass: "label",
labelAnchor: new google.maps.Point(20, 0),
});
google.maps.event.addListener(marker,"click", function() {
showInfo(marker);
$.getJSON("articles.php", { geo: place.postal_code
})
.done(function(articles, textStatus, jqXHR)
{
if(articles.length!=0)
{
var list="<ul>";
var template = _.template("<li><a href = '<%- link %>' target = '_blank'><%- title %></a></li>");
for(var i=0,n=articles.length;i<n;i++)
{
list+=template({
link: articles[i].link,
title: articles[i].title
});
}
list+="</ul>";
showInfo(marker,list);
}
else if(articles.length===0)
{
showInfo(marker,"No news today here");
}
});
});
markers.push(marker);
}