Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在弹出窗口中获取标记的纬度和经度)
问题描述
我使用 Leaflet Draw 插件.
我的目标是创建标记并显示一个弹出窗口,我可以在其中获取纬度和经度坐标.
我设法通过 javascript 警报获取这些坐标,但我绝对不知道如何将坐标放入我的弹出窗口中.
I use the Leaflet Draw plugin.
My goal is to create markers and show a pop up in which I can get latitude and longitude coordinates.
I manage to get these coordinates with a javascript alert but I definitely don't know how to put the coordinates into my pop up.
这是片段:
map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
if (type === 'marker') {
map.on('click', function(e) {
var lat = e.latlng.lat;
var lng = e.latlng.lng;
alert ("Latitude : " + lat + "
Longitude : " + lng);
}),
layer.bindPopup(
'e.latlng.lat');
}
drawnItems.addLayer(layer);
});
但它不起作用.弹出窗口显示e.latlng.lat",而我想要确切的值.
你有什么解决办法吗?谢谢.
But it does not work. The pop up shows "e.latlng.lat" whereas I'd want to have the exact value.
Have you any solutions ? Thanks.
推荐答案
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();
}
});
这篇关于Leaflet - 在弹出窗口中获取标记的纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Leaflet - 在弹出窗口中获取标记的纬度和经度
基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
