Class LngLat
Index
Constructors
constructor
Parameters
- lng: number
Longitude, measured in degrees.
- lat: number
Latitude, measured in degrees.
Returns LngLat
- lng: number
Properties
lat
Latitude, measured in degrees.
lng
Longitude, measured in degrees.
Methods
distanceTo
Returns the approximate distance between a pair of coordinates in meters Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)
Parameters
- lngLat: LngLat
coordinates to compute the distance to
Returns number
Distance in meters between the two coordinates.
- lngLat: LngLat
toArray
toString
wrap
Returns a new
LngLatobject whose longitude is wrapped to the range (-180, 180).Returns LngLat
The wrapped
LngLatobject.
Staticconvert
Converts an array of two numbers or an object with
lngandlatorlonandlatproperties to aLngLatobject.If a
LngLatobject is passed in, the function returns it unchanged.Parameters
- input: LngLatLike
An array of two numbers or object to convert, or a
LngLatobject to return.
Returns LngLat
A new
LngLatobject, if a conversion occurred, or the originalLngLatobject.- input: LngLatLike
A
LngLatobject represents a given longitude and latitude coordinate, measured in degrees. These coordinates are based on the WGS84 (EPSG:4326) standard.MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match the GeoJSON specification.
Note that any MapLibre GL JS method that accepts a
LngLatobject as an argument or option can also accept anArrayof two numbers and will perform an implicit conversion. This flexible type is documented as LngLatLike.Example
See
Get coordinates of the mouse pointer