0

When I load mashup the markers' info box show up as the page loads and then won't respond to clicks. I can make it work by changing the code to the bottom (but that doesn't use the spec for making the info box).

        // TODO
        var myLatLng = {lat: mylat, lng: mylng};

        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title: "Hello, world!"
        });

        // var infowindow = new google.maps.InfoWindow({
        // content: "test"
        // });

        marker.addListener('click', showInfo(marker, "test"));

Here is the version that works for markers (but doesn't call the spec function of showInfo):

        // TODO
        var myLatLng = {lat: mylat, lng: mylng};

        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title: "Hello, world!"
        });

        var infowindow = new google.maps.InfoWindow({
        content: "test"
        });

        marker.addListener('click', function() {infowindow.open(map, marker)});
-1

From https://developers.google.com/maps/documentation/javascript/events#EventListeners

To register for event notifications, use the addListener() event handler. That method takes an event to listen for, and a function to call when the specified event occurs.

The second argument is the function to call when specified event occurs.

marker.addListener('click', showInfo(marker, "test")); is an incorrect way of passing showInfo() function. The proper way would be

marker.addListener('click', function(){
    showInfo(marker, "test"));
}
| improve this answer | |

You must log in to answer this question.

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