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