So right clicking creates the markers but when i click on the marker the infowindow does not display.The commented alert gives the coordinates though. What could i be doing wrong. Is there a problem with the logic or the syntax. I can’t find my way around this problem. Here is my code:
// create marker on right click
google.maps.event.addListener(map,'rightclick', function(e) {
marker = new google.maps.Marker({
position: e.latLng,
map: map
});
alert('coord: ' + marker.getPosition().toUrlValue(3));
});
// display info window on marker click
google.maps.event.addListener(marker,'click', function(event){
infowindow = new google.maps.InfoWindow({
map:map,
content:"coordinates:"+event.latLng.toUrlValue(),
position:event.latLng
});
infowindow.open(map,marker);
});
You should place the second event on same context of first one:
Hope this helps.