---
title: "LngLat | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Class LngLat

A `LngLat` object represents a given longitude and latitude coordinate, measured in degrees. These coordinates are based on the [WGS84 (EPSG:4326) standard](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).

MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match the [GeoJSON specification](https://tools.ietf.org/html/rfc7946).

Note that any MapLibre GL JS method that accepts a `LngLat` object as an argument or option can also accept an `Array` of two numbers and will perform an implicit conversion. This flexible type is documented as [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/).

#### Example[](#example)

```typescript
let ll = new LngLat(-123.9749, 40.7736);
ll.lng; // = -123.9749
```

#### See[](#see)

[Get coordinates of the mouse pointer](https://maplibre.org/maplibre-gl-js/docs/examples/get-coordinates-of-the-mouse-pointer/)

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[lat](#lat) [lng](#lng)

### Methods[](#methods)

[distanceTo](#distanceto) [toArray](#toarray) [toString](#tostring) [wrap](#wrap) [convert](#convert)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new LngLat(lng: number, lat: number): LngLat[](#constructorlnglat)
    
    #### Parameters
    
    -   lng: number
        
        Longitude, measured in degrees.
        
    -   lat: number
        
        Latitude, measured in degrees.
        
    
    #### Returns LngLat
    

## Properties[](#properties-1)

### lat[](#lat)

lat: number

Latitude, measured in degrees.

### lng[](#lng)

lng: number

Longitude, measured in degrees.

## Methods[](#methods-1)

### distanceTo[](#distanceto)

-   distanceTo(lngLat: LngLat): number[](#distanceto-1)
    
    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.
    
    #### Example[](#example-1)
    
    ```typescript
    let new_york = new LngLat(-74.0060, 40.7128);
    let los_angeles = new LngLat(-118.2437, 34.0522);
    new_york.distanceTo(los_angeles); // = 3935751.690893987, "true distance" using a non-spherical approximation is ~3966km
    ```
    

### toArray[](#toarray)

-   toArray(): \[number, number\][](#toarray-1)
    
    Returns the coordinates represented as an array of two numbers.
    
    #### Returns \[number, number\]
    
    The coordinates represented as an array of longitude and latitude.
    
    #### Example[](#example-2)
    
    ```typescript
    let ll = new LngLat(-73.9749, 40.7736);
    ll.toArray(); // = [-73.9749, 40.7736]
    ```
    

### toString[](#tostring)

-   toString(): string[](#tostring-1)
    
    Returns the coordinates represent as a string.
    
    #### Returns string
    
    The coordinates represented as a string of the format `'LngLat(lng, lat)'`.
    
    #### Example[](#example-3)
    
    ```typescript
    let ll = new LngLat(-73.9749, 40.7736);
    ll.toString(); // = "LngLat(-73.9749, 40.7736)"
    ```
    

### wrap[](#wrap)

-   wrap(): LngLat[](#wrap-1)
    
    Returns a new `LngLat` object whose longitude is wrapped to the range (-180, 180).
    
    #### Returns LngLat
    
    The wrapped `LngLat` object.
    
    #### Example[](#example-4)
    
    ```typescript
    let ll = new LngLat(286.0251, 40.7736);
    let wrapped = ll.wrap();
    wrapped.lng; // = -73.9749
    ```
    

### `Static`convert[](#convert)

-   convert(input: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)): LngLat[](#convert-1)
    
    Converts an array of two numbers or an object with `lng` and `lat` or `lon` and `lat` properties to a `LngLat` object.
    
    If a `LngLat` object is passed in, the function returns it unchanged.
    
    #### Parameters
    
    -   input: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)
        
        An array of two numbers or object to convert, or a `LngLat` object to return.
        
    
    #### Returns LngLat
    
    A new `LngLat` object, if a conversion occurred, or the original `LngLat` object.
    
    #### Example[](#example-5)
    
    ```typescript
    let arr = [-73.9749, 40.7736];
    let ll = LngLat.convert(arr);
    ll;   // = LngLat {lng: -73.9749, lat: 40.7736}
    ```
