---
title: "MaptilerGeolocateControl | 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 MaptilerGeolocateControl`Maptiler`

The MaptilerGeolocateControl is an extension of the original GeolocateControl with a few changes. In this version, the active mode persists as long as the location is still centered. This means it's robust to rotation, pitch and zoom.

#### Hierarchy ([View Summary](https://docs.maptiler.com/sdk-js/api-reference/hierarchy/#MaptilerGeolocateControl))

-   [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/)
    -   MaptilerGeolocateControl

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[options](#options)

### Methods[](#methods)

[fire](#fire) [listens](#listens) [off](#off) [on](#on) [onAdd](#onadd) [once](#once) [onRemove](#onremove) [setEventedParent](#seteventedparent) [trigger](#trigger)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new MaptilerGeolocateControl(  
        options: [GeolocateControlOptions](https://docs.maptiler.com/sdk-js/api-reference/types/GeolocateControlOptions/),  
    ): MaptilerGeolocateControl[](#constructormaptilergeolocatecontrol)
    
    #### Parameters
    
    -   options: [GeolocateControlOptions](https://docs.maptiler.com/sdk-js/api-reference/types/GeolocateControlOptions/)
        
        the control's options
        
    
    #### Returns MaptilerGeolocateControl
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[constructor](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#constructor)
    

## Properties[](#properties-1)

### options[](#options)

options: [GeolocateControlOptions](https://docs.maptiler.com/sdk-js/api-reference/types/GeolocateControlOptions/)

Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[options](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#options)

## Methods[](#methods-1)

### fire[](#fire)

-   fire(event: string | [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/), properties?: any): this[](#fire-1)
    
    #### Parameters
    
    -   event: string | [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/)
    -   `Optional`properties: any
    
    #### Returns this
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[fire](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#fire)
    

### listens[](#listens)

-   listens(type: string): boolean[](#listens-1)
    
    Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
    
    #### Parameters
    
    -   type: string
        
        The event type
        
    
    #### Returns boolean
    
    `true` if there is at least one registered listener for specified event type, `false` otherwise
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[listens](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#listens)
    

### off[](#off)

-   off(type: string, listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): this[](#off-1)
    
    Removes a previously registered event listener.
    
    #### Parameters
    
    -   type: string
        
        The event type to remove listeners for.
        
    -   listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        The listener function to remove.
        
    
    #### Returns this
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[off](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#off)
    

### on[](#on)

-   on(type: string, listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): [Subscription](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Subscription/)[](#on-1)
    
    Adds a listener to a specified event type.
    
    #### Parameters
    
    -   type: string
        
        The event type to add a listen for.
        
    -   listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        The function to be called when the event is fired. The listener function is called with the data object passed to `fire`, extended with `target` and `type` properties.
        
    
    #### Returns [Subscription](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Subscription/)
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[on](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#on)
    

### onAdd[](#onadd)

-   onAdd(map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/) | [Map](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/)): [HTMLElement](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.HTMLElement/)[](#onadd-1)
    
    Register a control on the map and give it a chance to register event listeners and resources. This method is called by [Map.addControl](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/#addcontrol) internally.
    
    #### Parameters
    
    -   map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/) | [Map](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/)
        
        the Map this control will be added to
        
    
    #### Returns [HTMLElement](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.HTMLElement/)
    
    The control's container element. This should be created by the control and returned by onAdd without being attached to the DOM: the map will insert the control's element into the DOM as necessary.
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[onAdd](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#onadd)
    

### once[](#once)

-   once(type: string, listener?: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): Promise<any\> | MaptilerGeolocateControl[](#once-1)
    
    Adds a listener that will be called only once to a specified event type.
    
    The listener will be called first time the event fires after the listener is registered.
    
    #### Parameters
    
    -   type: string
        
        The event type to listen for.
        
    -   `Optional`listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        The function to be called when the event is fired the first time.
        
    
    #### Returns Promise<any\> | MaptilerGeolocateControl
    
    `this` or a promise if a listener is not provided
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[once](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#once)
    

### onRemove[](#onremove)

-   onRemove(): void[](#onremove-1)
    
    Unregister a control on the map and give it a chance to detach event listeners and resources. This method is called by [Map.removeControl](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/#removecontrol) internally.
    
    #### Returns void
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[onRemove](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#onremove)
    

### setEventedParent[](#seteventedparent)

-   setEventedParent(parent?: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/) | null, data?: any): this[](#seteventedparent-1)
    
    Bubble all events fired by this instance of Evented to this parent instance of Evented.
    
    #### Parameters
    
    -   `Optional`parent: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/) | null
    -   `Optional`data: any
    
    #### Returns this
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[setEventedParent](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#seteventedparent)
    

### trigger[](#trigger)

-   trigger(): boolean[](#trigger-1)
    
    Programmatically request and move the map to the user's location.
    
    #### Returns boolean
    
    `false` if called before control was added to a map, otherwise returns `true`.
    
    #### Example[](#example)
    
    ```typescript
    // Initialize the geolocate control.
    let geolocate = new GeolocateControl({
     positionOptions: {
       enableHighAccuracy: true
     },
     trackUserLocation: true
    });
    // Add the control to the map.
    map.addControl(geolocate);
    map.on('load', () => {
      geolocate.trigger();
    });
    ```
    
    Inherited from [GeolocateControl](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/).[trigger](https://docs.maptiler.com/sdk-js/api-reference/classes/GeolocateControl/#trigger)
