Reputation: 3
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. Any help would be appreciated.
Upvotes: 0
Views: 872
Reputation: 11338
If you have an <input>
you need to add a value:
document.getElementById("idfromHTML").value = latitude;
if you have a other html element you need to change the innerHTML:
document.getElementById("idfromHTML").innerHTML = latitude;
Upvotes: 1