If Geolocation service is turned off the `onError` callback is invoked after `timeout` interval (if specified).
If `timeout` parameter is not specified then no callback is called.
## navigator.geolocation.watchPosition
Returns the device's current position when a change in position is detected.
When the device retrieves a new location, the `geolocationSuccess`
callback executes with a `Position` object as the parameter. If
there is an error, the `geolocationError` callback executes with a
`PositionError` object as the parameter.
var watchId = navigator.geolocation.watchPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
### Parameters
- __geolocationSuccess__: The callback that is passed the current position.
- __geolocationError__: (Optional) The callback that executes if an error occurs.
- __geolocationOptions__: (Optional) The geolocation options.
### Returns
- __String__: returns a watch id that references the watch position interval. The watch id should be used with `navigator.geolocation.clearWatch` to stop watching for changes in position.
### Example
// onSuccess Callback
// This method accepts a `Position` object, which contains
// the current GPS coordinates
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
- __enableHighAccuracy__: Provides a hint that the application needs the best possible results. By default, the device attempts to retrieve a `Position` using network-based methods. Setting this property to `true` tells the framework to use more accurate methods, such as satellite positioning. _(Boolean)_
- __timeout__: The maximum length of time (milliseconds) that is allowed to pass from the call to `navigator.geolocation.getCurrentPosition` or `geolocation.watchPosition` until the corresponding `geolocationSuccess` callback executes. If the `geolocationSuccess` callback is not invoked within this time, the `geolocationError` callback is passed a `PositionError.TIMEOUT` error code. (Note that when used in conjunction with `geolocation.watchPosition`, the `geolocationError` callback could be called on an interval every `timeout` milliseconds!) _(Number)_
- __maximumAge__: Accept a cached position whose age is no greater than the specified time in milliseconds. _(Number)_
### Android Quirks
If Geolocation service is turned off the `onError` callback is invoked after `timeout` interval (if specified).
If `timeout` parameter is not specified then no callback is called.
## navigator.geolocation.clearWatch
Stop watching for changes to the device's location referenced by the
`watchID` parameter.
navigator.geolocation.clearWatch(watchID);
### Parameters
- __watchID__: The id of the `watchPosition` interval to clear. (String)
### Example
// Options: watch for changes in position, and use the most
// accurate position acquisition method available.
//
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });
// ...later on...
navigator.geolocation.clearWatch(watchID);
## Position
Contains `Position` coordinates and timestamp, created by the geolocation API.
### Properties
- __coords__: A set of geographic coordinates. _(Coordinates)_
- __timestamp__: Creation timestamp for `coords`. _(DOMTimeStamp)_
## Coordinates
A `Coordinates` object is attached to a `Position` object that is
available to callback functions in requests for the current position.
It contains a set of properties that describe the geographic coordinates of a position.
### Properties
* __latitude__: Latitude in decimal degrees. _(Number)_
* __longitude__: Longitude in decimal degrees. _(Number)_
* __altitude__: Height of the position in meters above the ellipsoid. _(Number)_
* __accuracy__: Accuracy level of the latitude and longitude coordinates in meters. _(Number)_
* __altitudeAccuracy__: Accuracy level of the altitude coordinate in meters. _(Number)_
* __heading__: Direction of travel, specified in degrees counting clockwise relative to the true north. _(Number)_
* __speed__: Current ground speed of the device, specified in meters per second. _(Number)_
### Amazon Fire OS Quirks
__altitudeAccuracy__: Not supported by Android devices, returning `null`.
### Android Quirks
__altitudeAccuracy__: Not supported by Android devices, returning `null`.
## PositionError
The `PositionError` object is passed to the `geolocationError`
callback function when an error occurs with navigator.geolocation.
### Properties
- __code__: One of the predefined error codes listed below.
- __message__: Error message describing the details of the error encountered.
### Constants
-`PositionError.PERMISSION_DENIED`
- Returned when users do not allow the app to retrieve position information. This is dependent on the platform.
-`PositionError.POSITION_UNAVAILABLE`
- Returned when the device is unable to retrieve a position. In general, this means the device is not connected to a network or can't get a satellite fix.
-`PositionError.TIMEOUT`
- Returned when the device is unable to retrieve a position within the time specified by the `timeout` included in `geolocationOptions`. When used with `navigator.geolocation.watchPosition`, this error could be repeatedly passed to the `geolocationError` callback every `timeout` milliseconds.