Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Lat, Long of a clicked location using leaflet Api

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:

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

like image 771
troy Avatar asked Nov 01 '12 10:11

troy


People also ask

How do you find the current location in a leaflet?

Show current user location The leaflet can also show the view based on the current location by using locate() method. It takes in an object that has setView property set to true and a maxZoom value set to a maximum value. This command will ask for the user's location and automatically set the view to that location.

How do I find LAT LNG address?

On the Google Maps app, you can't pull up a context menu. To find the address for your coordinates, hold your finger down over the red pin that shows your coordinates. Then, after 1-3 seconds, the address will pop up on the bottom of your screen.

What is LatLng in leaflet?

Represents a geographical point with a certain latitude and longitude.


1 Answers

map.on('click', function(e) {
    alert(e.latlng);
});

Docs

like image 124
bentrm Avatar answered Oct 07 '22 01:10

bentrm