开发者

google map V-3 simple problem with latlng

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(); 
  开发者_StackOverflow中文版      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


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); 
}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜