0

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

1
  • It turns out I was only missing the var keyword for my variable called marker. Now everything works fine!
    – Carlos C
    Commented Dec 19, 2016 at 3:31

1 Answer 1

0

It turns out I was only missing the var keyword for my variable called marker. Now everything works fine!

You must log in to answer this question.

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