how to click on a map and capture the location?
I'm new to google maps API and need directions.
I want to let a user navigate a map (embedded in my page) and when she clicks, I want to capture the location and save it somehow.
I'm using rails 3 and have been l开发者_StackOverflow社区ooking for a gem or plugin, but only thing I found was YM4R/GM that's apparently using an old GM api and only works with rails 2...
If the answer is RTFM the Google-maps api v3, I apologize ;-)
Like this :
google.maps.event.addListener(map, 'click', function(event) {
alert(event.latLng.lat());
alert(event.latLng.lng());
});
Google code playground gathers a bunch a code samples related to Google API. Moreover, it provides a embedded IDE which allow to easily try out some code on the fly.
This piece of code should help you in retrieving the clicked location.
精彩评论