Jeppe Liisberg
Jeppe Liisberg

Reputation: 3804

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 looking 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 ;-)

Upvotes: 0

Views: 422

Answers (2)

nulltoken
nulltoken

Reputation: 67589

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.

Upvotes: 0

aurels
aurels

Reputation: 801

Like this :

google.maps.event.addListener(map, 'click', function(event) {
    alert(event.latLng.lat());
    alert(event.latLng.lng());
});

Upvotes: 1

Related Questions