Solved

Google maps right click event error

Posted on 2013-06-21
4
453 Views
Last Modified: 2013-06-21
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
Comment
Question by:shahjagat
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 200 total points
Comment Utility
put line 23 to 27 inside the initialize function (line 23 is good)
test page : http://jsfiddle.net/7vqrc/
0
 

Author Comment

by:shahjagat
Comment Utility
leakim971, it worked.
Do you need to have all the events inside initialize?
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
for click on the map, yes
0
 

Author Closing Comment

by:shahjagat
Comment Utility
thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now