Class: Geolocation

ol/Geolocation~Geolocation


import Geolocation from 'ol/Geolocation';

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

To get notified of position changes, register a listener for the generic change event on your instance of module:ol/Geolocation~Geolocation.

Example:

var 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) {
  window.console.log(geolocation.getPosition());
});

new Geolocation(opt_options)

Geolocation.js, line 48
Name Type Description
options

Options.

Name Type Default Description
tracking boolean false

Start Tracking right after instantiation.

trackingOptions PositionOptions

Tracking options. See http://www.w3.org/TR/geolocation-API/#position_options_interface.

projection module:ol/proj~ProjectionLike

The projection the position is reported in.

Fires:
  • error - Triggered when the Geolocation returns an error.

Methods

getAccuracy(){number|undefined}

Geolocation.js, line 189

Get the accuracy of the position in meters.

Returns:
The accuracy of the position measurement in meters.

getAccuracyGeometry(){module:ol/geom/Polygon~Polygon}

Geolocation.js, line 199

Get a geometry of the position accuracy.

Returns:
A geometry of the position accuracy.

getAltitude(){number|undefined}

Geolocation.js, line 212

Get the altitude associated with the position.

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

getAltitudeAccuracy(){number|undefined}

Geolocation.js, line 223

Get the altitude accuracy of the position.

Returns:
The accuracy of the altitude measurement in meters.

getHeading(){number|undefined}

Geolocation.js, line 235

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:
The heading of the device in radians from north.

getPosition(){module:ol/coordinate~Coordinate|undefined}

Geolocation.js, line 246

Get the position of the device.

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

getProjection(){module:ol/proj/Projection~Projection|undefined}

Geolocation.js, line 259

Get the projection associated with the position.

Returns:
The projection the position is reported in.

getSpeed(){number|undefined}

Geolocation.js, line 272

Get the speed in meters per second.

Returns:
The instantaneous speed of the device in meters per second.

getTracking(){boolean}

Geolocation.js, line 282

Determine if the device location is being tracked.

Returns:
The device location is being tracked.

getTrackingOptions(){PositionOptions|undefined}

Geolocation.js, line 295

Get the tracking options. See http://www.w3.org/TR/geolocation-API/#position-options.

Returns:
PositionOptions as defined by the HTML5 Geolocation spec .

setProjection(projection)

Geolocation.js, line 306

Set the projection to use for transforming the coordinates.

Name Type Description
projection module:ol/proj~ProjectionLike

The projection the position is reported in.

setTracking(tracking)

Geolocation.js, line 316

Enable or disable tracking.

Name Type Description
tracking boolean

Enable tracking.

setTrackingOptions(options)

Geolocation.js, line 329

Set the tracking options. See http://www.w3.org/TR/geolocation-API/#position-options.

Name Type Description
options PositionOptions

PositionOptions as defined by the HTML5 Geolocation spec .