I want to know how to trigger an event when I click on an infoWindow using Google Maps API v3. In this example, when I click on a marker, an info window shows up with a uni
The InfoWindow object does not have a 'click' event, so you cannot do
google.maps.event.addListener(infowindow, 'click',....
instead, you can attach an event handler to the DOM object, such as
function addMarker(latLng, name){
var marker = new google.maps.Marker({
map:map,
position:latLng
});
G.event.addListener(marker,'click',function(mev){
var div = document.createElement('div');
div.innerHTML = name;
div.onclick = function(){iwClick(name)};
infoWindow.setContent(div);
infoWindow.setPosition(mev.latLng);
infoWindow.open(map);
});
}
function iwClick(str){
alert(str);
};
and you call it with
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
addMarker(chicago,'chicago');