LatLng
Quick answer
L.latLng represents a geographic coordinate with lat, lng and an optional alt, and nearly every position argument in Leaflet is normalized into it. Construct it from two numbers, an array or a plain object depending on where the data comes from.
L.latLng( lat , lng , alt? ) → LatLng
Key points
- Passing an existing LatLng returns the same object; call clone when isolation is needed.
- distanceTo returns spherical meters using a 6371000 meter sphere approximation.
- wrap folds longitudes back into the minus 180 to 180 range.
Example
var a = L.latLng(39.907359, 116.391263);
var b = L.latLng(39.914700, 116.410600);
console.log(a.distanceTo(b)); // 约 2360 米
console.log(a.toBounds(1000)); // 边长约 1 km 的矩形
console.log(L.latLng(10, 190).wrap()); // 经度折回 -170var bounds = L.latLngBounds([[39.88, 116.30], [39.95, 116.48]]);
bounds.extend([40.00, 116.55]);
map.fitBounds(bounds, { padding: [20, 20] });
console.log(bounds.toBBoxString());
Notes
- Comparing coordinates with strict equality almost always fails; use equals with a margin.
- wrap handles one point only and does not fix shortest paths across the antimeridian.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). LatLng. https://www.jingweizhi.com/en/leaflet/api/latlng.html (accessed 2026-11-03).