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

馋奶兔 提交于 2019-12-06 22:51:34

问题


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


回答1:


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

Docs



来源:https://stackoverflow.com/questions/13175101/how-to-get-the-lat-long-of-a-clicked-location-using-leaflet-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!