0

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

}

0

I'm really happy that I have found answer for my own question. After a serious search on this problem, I got the one that caused the error. The error occurred because that the last added marker is fixed for showing the infoWindow. To avoid this, load articles for all the markers with an unique "code" and then view the infoWindow on clicked. :)

You must log in to answer this question.

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