本文介紹了Leaflet - 在彈出窗口中獲取標記的緯度和經(jīng)度的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我使用 Leaflet Draw 插件.
我的目標是創(chuàng)建標記并顯示一個彈出窗口,我可以在其中獲取緯度和經(jīng)度坐標.
我設法通過 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 - 在彈出窗口中獲取標記的緯度和經(jīng)度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!