Classdesc

Helper class for providing HTML5 Geolocation capabilities. The Geolocation API is used to locate a user's position.

To get notified of position changes and errors, register listeners for the generic change event and the error event on your instance of module:ol/Geolocation~Geolocation.

Example:

const geolocation = new Geolocation({
// take the projection to use from the map's view
projection: view.getProjection()
});
// listen to changes in position
geolocation.on('change', function(evt) {
console.log(geolocation.getPosition());
});
// listen to error
geolocation.on('error', function(evt) {
window.console.log(evt.message);
});

Fires

GeolocationError

Api

Hierarchy (view full)

Constructors

Properties

disposed: boolean

The object has already been disposed.

on: GeolocationOnSignature<EventsKey>
once: GeolocationOnSignature<EventsKey>
un: GeolocationOnSignature<void>

Methods

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Protected

    Apply any properties from another object without triggering events.

    Parameters

    • source: Object

      The source object.

    Returns void

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

    Api

  • Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a type property.

    Parameters

    • event: string | BaseEvent

      Event object.

    Returns undefined | boolean

    false if anyone called preventDefault on the event object or if any of the listeners returned false.

    Api

  • Clean up.

    Returns void

  • Protected

    Extension point for disposable objects.

    Returns void

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

  • Get the accuracy of the position in meters.

    Returns undefined | number

    The accuracy of the position measurement in meters.

    Observable

    Api

  • Get a geometry of the position accuracy.

    Returns null | Polygon

    A geometry of the position accuracy.

    Observable

    Api

  • Get the altitude associated with the position.

    Returns undefined | number

    The altitude of the position in meters above mean sea level.

    Observable

    Api

  • Get the altitude accuracy of the position.

    Returns undefined | number

    The accuracy of the altitude measurement in meters.

    Observable

    Api

  • Get the heading as radians clockwise from North. Note: depending on the browser, the heading is only defined if the enableHighAccuracy is set to true in the tracking options.

    Returns undefined | number

    The heading of the device in radians from north.

    Observable

    Api

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

  • Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.

    Parameters

    • type: string

      Type.

    Returns undefined | Listener[]

    Listeners.

  • Get the position of the device.

    Returns undefined | Coordinate

    The current position of the device reported in the current projection.

    Observable

    Api

  • Get the projection associated with the position.

    Returns undefined | Projection

    The projection the position is reported in.

    Observable

    Api

  • Get an object of all property names and values.

    Returns {
        [x: string]: any;
    }

    Object.

    • [x: string]: any

    Api

  • Get an object of all property names and values.

    Returns null | {
        [x: string]: any;
    }

    Object.

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

    Api

  • Get the speed in meters per second.

    Returns undefined | number

    The instantaneous speed of the device in meters per second.

    Observable

    Api

  • Determine if the device location is being tracked.

    Returns boolean

    The device location is being tracked.

    Observable

    Api

  • Parameters

    • Optional type: string

      Type. If not provided, true will be returned if this event target has any listeners.

    Returns boolean

    Has listeners.

  • Returns boolean

    The object has properties.

  • Parameters

    • key: string

      Key name.

    • oldValue: any

      Old value.

    Returns void

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Set the projection to use for transforming the coordinates.

    Parameters

    • projection: ProjectionLike

      The projection the position is reported in.

    Returns void

    Observable

    Api

  • Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

    Parameters

    • values: {
          [x: string]: any;
      }

      Values.

      • [x: string]: any
    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Enable or disable tracking.

    Parameters

    • tracking: boolean

      Enable tracking.

    Returns void

    Observable

    Api

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional silent: boolean

      Unset without triggering an event.

    Returns void

    Api