越来越懒,使用Leaflet API的点击位置很长吗?


16

我将OSM与Leaflet API一起使用。现在,我想获取单击位置的经纬度。我的意思与此类似。例如: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));

        });

OpenLayers中的这段代码有助于获取经度,长期价值...使用Leaflet寻找类似内容...

Answers:


50

您可以使用地图的“ on”事件订阅方法轻松获得点击事件:

map.on('click', function(e) {
    alert("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng)
});
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.