---
title: "LngLatBounds | 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 LngLatBounds

A `LngLatBounds` object represents a geographical bounding box, defined by its southwest and northeast points in longitude and latitude.

If no arguments are provided to the constructor, a `null` bounding box is created.

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

#### Example[](#example)

```typescript
let sw = new LngLat(-73.9876, 40.7661);
let ne = new LngLat(-73.9397, 40.8002);
let llb = new LngLatBounds(sw, ne);
```

#### See[](#see)

[Fit to the bounds of a LineString](https://maplibre.org/maplibre-gl-js/docs/examples/fit-to-the-bounds-of-a-linestring/)

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Methods[](#methods)

[adjustAntiMeridian](#adjustantimeridian) [contains](#contains) [extend](#extend) [getCenter](#getcenter) [getEast](#geteast) [getNorth](#getnorth) [getNorthEast](#getnortheast) [getNorthWest](#getnorthwest) [getSouth](#getsouth) [getSouthEast](#getsoutheast) [getSouthWest](#getsouthwest) [getWest](#getwest) [intersects](#intersects) [isEmpty](#isempty) [setNorthEast](#setnortheast) [setSouthWest](#setsouthwest) [toArray](#toarray) [toString](#tostring) [convert](#convert) [fromLngLat](#fromlnglat)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new LngLatBounds(  
        sw?:  
            | \[number, number, number, number\]  
            | [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)  
            | \[[LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/), [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)\],  
        ne?: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/),  
    ): LngLatBounds[](#constructorlnglatbounds)
    
    #### Parameters
    
    -   `Optional`sw: \[number, number, number, number\] | [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/) | \[[LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/), [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)\]
        
        The southwest corner of the bounding box. OR array of 4 numbers in the order of west, south, east, north OR array of 2 LngLatLike: \[sw,ne\]
        
    -   `Optional`ne: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)
        
        The northeast corner of the bounding box.
        
    
    #### Returns LngLatBounds
    
    #### Example[](#example-1)
    
    ```typescript
    let sw = new LngLat(-73.9876, 40.7661);
    let ne = new LngLat(-73.9397, 40.8002);
    let llb = new LngLatBounds(sw, ne);
    ```
    
    OR
    
    ```typescript
    let llb = new LngLatBounds([-73.9876, 40.7661, -73.9397, 40.8002]);
    ```
    
    OR
    
    ```typescript
    let llb = new LngLatBounds([sw, ne]);
    ```
## Methods[](#methods-1)

### adjustAntiMeridian[](#adjustantimeridian)

-   adjustAntiMeridian(): LngLatBounds[](#adjustantimeridian-1)
    
    Adjusts the given bounds to handle the case where the bounds cross the 180th meridian (antimeridian).
    
    #### Returns LngLatBounds
    
    The adjusted LngLatBounds
    
    #### Example[](#example-2)
    
    ```typescript
    let bounds = new LngLatBounds([175.813127, -20.157768], [-178. 340903, -15.449124]);
    let adjustedBounds = bounds.adjustAntiMeridian();
    // adjustedBounds will be: [[175.813127, -20.157768], [181.659097, -15.449124]]
    ```
    

### contains[](#contains)

-   contains(lnglat: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)): boolean[](#contains-1)
    
    Check if the point is within the bounding box.
    
    #### Parameters
    
    -   lnglat: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)
        
        geographic point to check against.
        
    
    #### Returns boolean
    
    `true` if the point is within the bounding box.
    
    #### Example[](#example-3)
    
    ```typescript
    let llb = new LngLatBounds(
      new LngLat(-73.9876, 40.7661),
      new LngLat(-73.9397, 40.8002)
    );
    
    let ll = new LngLat(-73.9567, 40.7789);
    
    console.log(llb.contains(ll)); // = true
    ```
    

### extend[](#extend)

-   extend(obj: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/) | [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/)): this[](#extend-1)
    
    Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
    
    #### Parameters
    
    -   obj: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/) | [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/)
        
        object to extend to
        
    
    #### Returns this
    

### getCenter[](#getcenter)

-   getCenter(): [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)[](#getcenter-1)
    
    Returns the geographical coordinate equidistant from the bounding box's corners.
    
    #### Returns [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    
    The bounding box's center.
    
    #### Example[](#example-4)
    
    ```typescript
    let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
    llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
    ```
    

### getEast[](#geteast)

-   getEast(): number[](#geteast-1)
    
    Returns the east edge of the bounding box.
    
    #### Returns number
    
    The east edge of the bounding box.
    

### getNorth[](#getnorth)

-   getNorth(): number[](#getnorth-1)
    
    Returns the north edge of the bounding box.
    
    #### Returns number
    
    The north edge of the bounding box.
    

### getNorthEast[](#getnortheast)

-   getNorthEast(): [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)[](#getnortheast-1)
    
    Returns the northeast corner of the bounding box.
    
    #### Returns [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    
    The northeast corner of the bounding box.
    

### getNorthWest[](#getnorthwest)

-   getNorthWest(): [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)[](#getnorthwest-1)
    
    Returns the northwest corner of the bounding box.
    
    #### Returns [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    
    The northwest corner of the bounding box.
    

### getSouth[](#getsouth)

-   getSouth(): number[](#getsouth-1)
    
    Returns the south edge of the bounding box.
    
    #### Returns number
    
    The south edge of the bounding box.
    

### getSouthEast[](#getsoutheast)

-   getSouthEast(): [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)[](#getsoutheast-1)
    
    Returns the southeast corner of the bounding box.
    
    #### Returns [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    
    The southeast corner of the bounding box.
    

### getSouthWest[](#getsouthwest)

-   getSouthWest(): [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)[](#getsouthwest-1)
    
    Returns the southwest corner of the bounding box.
    
    #### Returns [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
    
    The southwest corner of the bounding box.
    

### getWest[](#getwest)

-   getWest(): number[](#getwest-1)
    
    Returns the west edge of the bounding box.
    
    #### Returns number
    
    The west edge of the bounding box.
    

### intersects[](#intersects)

-   intersects(other: [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/)): boolean[](#intersects-1)
    
    Checks if this bounding box intersects with another bounding box.
    
    Returns true if the bounding boxes share any area, including cases where they only touch along an edge or at a corner.
    
    This method properly handles cases where either or both bounding boxes cross the antimeridian (date line).
    
    #### Parameters
    
    -   other: [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/)
    
    #### Returns boolean
    

### isEmpty[](#isempty)

-   isEmpty(): boolean[](#isempty-1)
    
    Check if the bounding box is an empty/`null`\-type box.
    
    #### Returns boolean
    
    True if bounds have been defined, otherwise false.
    

### setNorthEast[](#setnortheast)

-   setNorthEast(ne: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)): this[](#setnortheast-1)
    
    Set the northeast corner of the bounding box
    
    #### Parameters
    
    -   ne: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)
        
        a [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/) object describing the northeast corner of the bounding box.
        
    
    #### Returns this
    

### setSouthWest[](#setsouthwest)

-   setSouthWest(sw: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)): this[](#setsouthwest-1)
    
    Set the southwest corner of the bounding box
    
    #### Parameters
    
    -   sw: [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/)
        
        a [LngLatLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatLike/) object describing the southwest corner of the bounding box.
        
    
    #### Returns this
    

### toArray[](#toarray)

-   toArray(): \[\[number, number\], \[number, number\]\][](#toarray-1)
    
    Returns the bounding box represented as an array.
    
    #### Returns \[\[number, number\], \[number, number\]\]
    
    The bounding box represented as an array, consisting of the southwest and northeast coordinates of the bounding represented as arrays of numbers.
    
    #### Example[](#example-5)
    
    ```typescript
    let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
    llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
    ```
    

### toString[](#tostring)

-   toString(): string[](#tostring-1)
    
    Return the bounding box represented as a string.
    
    #### Returns string
    
    The bounding box represents as a string of the format `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
    
    #### Example[](#example-6)
    
    ```typescript
    let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
    llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
    ```
    

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

-   convert(input: [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/) | null): LngLatBounds[](#convert-1)
    
    Converts an array to a `LngLatBounds` object.
    
    If a `LngLatBounds` object is passed in, the function returns it unchanged.
    
    Internally, the function calls [LngLat.convert](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/#convert) to convert arrays to `LngLat` values.
    
    #### Parameters
    
    -   input: [LngLatBoundsLike](https://docs.maptiler.com/sdk-js/api-reference/types/LngLatBoundsLike/) | null
        
        An array of two coordinates to convert, or a `LngLatBounds` object to return.
        
    
    #### Returns LngLatBounds
    
    A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
    
    #### Example[](#example-7)
    
    ```typescript
    let arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
    let llb = LngLatBounds.convert(arr); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
    ```
    

### `Static`fromLngLat[](#fromlnglat)

-   fromLngLat(center: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/), radius?: number): LngLatBounds[](#fromlnglat-1)
    
    Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
    
    #### Parameters
    
    -   center: [LngLat](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.LngLat/)
        
        center coordinates of the new bounds.
        
    -   `Optional`radius: number
        
        Distance in meters from the coordinates to extend the bounds.
        
    
    #### Returns LngLatBounds
    
    A new `LngLatBounds` object representing the coordinates extended by the `radius`.
    
    #### Example[](#example-8)
    
    ```typescript
    let center = new LngLat(-73.9749, 40.7736);
    LngLatBounds.fromLngLat(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
    ```
