views:

73

answers:

1

hi, i was using v2 of google maps. Now i shifted to v3.

In version 2, this WAS working

    GEvent.addListener(map, "click", function(overlay, latlng) { 
        myLatitude = latlng.lat(); 
        myLongitude = latlng.lng(); 
        alert(myLatitude + '  data  ' + myLongitude); 
    }); 

what should be the equvalant of this code in v3 ?? i searched a lot, but couldn't find any good result..

I have tried this..

    google.maps.event.addListener(map, 'click', function(overlay , latlng) { 
        myLatitude = latlng.lat(); 
        //myLongitude = latlng.lng(); 
        alert('hi! ' + myLatitude); 
    }); 

but no results..

thanks

+2  A: 

If you look at the docs: http://code.google.com/apis/maps/documentation/v3/reference.html#Map

You'll see that the 'click' event passes a MouseEvent argument, which has a property latLng, so your method signature above is wrong, this should work:

google.maps.event.addListener(map, 'click', function(e) { 
    myLatitude = e.latLng.lat(); 
    alert('hi! ' + myLatitude); 
}); 
Ossama