Link to home
Start Free TrialLog in
Avatar of shahjagat
shahjagatFlag for United States of America

asked on

Google maps right click event error

Hi,

I am trying to add a right click event to the google maps.  I cannot see alert with the geocodes.
I am not sure what to change.


var map;


var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  map = new google.maps.Map(document.getElementById('mapsGoogle'),
      mapOptions);
      directionsDisplay.setMap(map);
      directionsDisplay.setPanel(document.getElementById('directions-panel'));
      HomeTestMarker();

}

 google.maps.event.addListener(map, 'rightclick', function(event ) {
         var lat = event.latLng.lat();
         var lng = event.latLng.lng();
        alert("Lat=" + lat + "; Lng=" + lng);
    });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shahjagat

ASKER

leakim971, it worked.
Do you need to have all the events inside initialize?
for click on the map, yes
thanks