如何使用Leaflet Api获取所点击位置的纬度和经度

9
我正在使用leaflet API的OSM。现在我想获取所点击位置的纬度和经度。我的意思是类似于这个例子的东西: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));

        });

这段代码在open layers中帮助获取经纬度数值 - 寻找类似的使用leaflet。任何帮助都将非常棒。先行致谢。
1个回答

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

文档


如果您使用TypeScript,请记住关于e: L.MouseEvent - kcpr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接