Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

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

0
shahjagat
Asked:
shahjagat
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
put line 23 to 27 inside the initialize function (line 23 is good)
test page : http://jsfiddle.net/7vqrc/
0
 
shahjagatAuthor Commented:
leakim971, it worked.
Do you need to have all the events inside initialize?
0
 
leakim971PluritechnicianCommented:
for click on the map, yes
0
 
shahjagatAuthor Commented:
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now