admin管理员组

文章数量:1389829

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 !

Share Improve this question edited May 23, 2017 at 10:26 CommunityBot 11 silver badge asked Jul 2, 2014 at 21:45 JulienJulien 6293 gold badges17 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9
layer.getLatLng().lat.toFixed(3)

See the JavaScript number object.

本文标签: javascriptLeafletget the first three decimals of Longitude and LatitudeStack Overflow