-1

I am jrying to convert the following 2 google m aps V2 API events to V3 but cannot for the life of me figure out how to do it, would it be possible for someone to give me some pointers on this?

    GEvent.addListener(map, "click", function(overlay, point){
    if (point != null) {
      window.status = "Click " + point.lat() + ", "+ point.lng();
    } 
          else if (overlay != null) 
        {
      window.status = "Overlay " + lastPoint.lat() + ", "+ lastPoint.lng();
    }
});
GEvent.addListener(map, "mousemove", function(point){
 lastPoint = point;
});
4
  • 2
    What is exactly your problem?
    – akluth
    Apr 25, 2013 at 15:03
  • I cannot find the equivelent for map, "click", function(overlay, point)
    – colin
    Apr 25, 2013 at 15:29
  • Please note that tags stand alone. Tagging this question with google, maps and api does not mean you are talking about the Google Maps API for Javascript.
    – Charles
    Apr 25, 2013 at 16:24
  • 2

2 Answers 2

1

Try this:

google.maps.event.addListener(map, 'click', function(event) {
  console.log(event.latLng);
});

"No overlay argument exists in v3 event listeners. If you register a click event on a v3 map the callback will only occur when the user clicks on the base map. You can register additional callbacks on clickable overlays if you need to react to those clicks. " - https://developers.google.com/maps/articles/v2tov3#events

0

if you need click through overlay and let overlay clickable, propagate click from overlay:

var map = new google.maps.Map(document.getElementById("mapcanvas"), mapOptions);

google.maps.event.addListener(map, 'click', function(event) {
    console.log(event.latLng);
});

google.maps.event.addListener(overlay, 'click', function(event) {
    google.maps.event.trigger(map, 'click', event);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.