My goal is to get Latitude and Longitude coordinates as soon as I draw a marker.
I managed to do that with that snippet (see Leaflet - get latitude and longitude of a marker inside a pop-up) :
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();
}
});
But I'd like to get the first three decimals of latitude and longitude, like 35.567 and 105.891.
Is it possible to do that with Leaflet and how ?
Thanks !
My goal is to get Latitude and Longitude coordinates as soon as I draw a marker.
I managed to do that with that snippet (see Leaflet - get latitude and longitude of a marker inside a pop-up) :
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();
}
});
But I'd like to get the first three decimals of latitude and longitude, like 35.567 and 105.891.
Is it possible to do that with Leaflet and how ?
Thanks !
1 Answer
Reset to default 9layer.getLatLng().lat.toFixed(3)
See the JavaScript number object.