我的目标是在绘制标记后立即获取纬度和经度坐标。
我设法用那个片段做到了这一点(参见 Leaflet - get latitude and longitude of a marker inside a pop-up):
map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
map.addLayer(layer);
if (type === 'marker') {
layer.bindPopup('LatLng: ' + layer.getLatLng()).openPopup();
}
});
但我想得到经纬度的前三位小数,比如 35.567 和 105.891。
是否可以用 Leaflet 做到这一点?如何做到?
谢谢!
最佳答案
layer.getLatLng().lat.toFixed(3)
关于javascript - Leaflet——获取经纬度的前三位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24541551/