[英]Save lat and lng on leaflet map click event
I am new to leaflet and js and I am looking for a way to get the latitude and longitude from a leaflet map on a click event and pass it into an HTML text input. I am new to leaflet and js and I am looking for a way to get the latitude and longitude from a leaflet map on a click event and pass it into an HTML text input.
I tried to use我试着用
map.on('click', function(e) {
var latitude = e.latlng.lat;
var longitude = e.latlng.lng;
var latt = document.getElementById("idfromHTML").innerHTML(latitude);
});
to save them on a variable, yet I cant seem to pass them in an HTML tag.将它们保存在变量中,但我似乎无法将它们传递到 HTML 标记中。 Any help would be appreciated.
任何帮助,将不胜感激。
If you have an <input>
you need to add a value:如果你有一个
<input>
你需要添加一个值:
document.getElementById("idfromHTML").value = latitude;
if you have a other html element you need to change the innerHTML:如果您有其他 html 元素,则需要更改 innerHTML:
document.getElementById("idfromHTML").innerHTML = latitude;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.