Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using OSM with leaflet API. Now i want to get the lat and long of a clicked location. I meant something similar to this. ex: http://openlayers.org/dev/examples/click.html

map.events.register("click", map, function(e) {
            var position = map.getLonLatFromPixel(e.xy);
                alert("Lat, Lon : "+position.lon.toFixed(3),position.lat.toFixed(3));

        });

This code in open layers helps to get the lat ,long values .... looking for something similar using leaflet........ Any help would be really great..... Thanks in advance

share|improve this question
up vote 4 down vote accepted

check out this example here may help you...

i have not used it before as you. it locates in Conversion Methods.

mouseEventToLatLng( event ) LatLng Returns the geographical coordinates of the point the mouse clicked on given the click's event object.

i hope it helps you...

share|improve this answer
    
Cheers.. this example helped me.... – DomincJune Nov 1 '12 at 12:35
5  
Link is broken. – Christoph Dec 30 '14 at 17:38

You can easily get click events using the map's 'on' event subscription method:

map.on('click', function(e) {
    alert("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng)
});
share|improve this answer
    
need to close parenthesis at the end. – s2t2 Nov 7 '14 at 2:27
    
much better than the accepted answer. – Sumit Jan 15 at 13:37
    
is the 'on' method coming from the leaflet.js library or mapbox? – maxwell Apr 11 at 22:53

map.on('click', function(e) { alert("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng) })

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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