Geolocation Class

The Geolocation API of a window (https://w3c.github.io/geolocation/#geolocation_interface, navigator.geolocation): the positions of the device, read from the GeolocationProvider of the browsing context (BrowsingContextOptions.Geolocation).

public sealed class Geolocation

Remarks

The positions are only given to the documents of a secure context that are allowed to use the geolocation feature by their permissions policy and whose geolocation permission is granted (see BrowsingContextOptions.RequestPermission). The requests of a hidden document wait until it is visible.

See also

Methods

NameDescription
ClearWatch(int)Stops a watch created by Geolocation.WatchPosition (https://w3c.github.io/geolocation/#clearwatch-method).
GetCurrentPosition(PositionCallback, PositionErrorCallback?, PositionOptions?)Requests the position of the device (https://w3c.github.io/geolocation/#getcurrentposition-method): the success callback is invoked with the position, or the error callback with the reason of the failure.
WatchPosition(PositionCallback, PositionErrorCallback?, PositionOptions?)Watches the position of the device (https://w3c.github.io/geolocation/#watchposition-method): the success callback is invoked with the position, then each time it changes, until Geolocation.ClearWatch is called. Returns the identifier of the watch (0 when the document is not fully active).

ClearWatch(int)

Geolocation.cs

Stops a watch created by Geolocation.WatchPosition (https://w3c.github.io/geolocation/#clearwatch-method).

public void ClearWatch(int watchId)

Parameters

watchId int
The identifier of the watch.

See also

GetCurrentPosition(PositionCallback, PositionErrorCallback?, PositionOptions?)

Geolocation.cs

Requests the position of the device (https://w3c.github.io/geolocation/#getcurrentposition-method): the success callback is invoked with the position, or the error callback with the reason of the failure.

public void GetCurrentPosition(PositionCallback successCallback, PositionErrorCallback? errorCallback = null, PositionOptions? options = null)

Parameters

successCallback PositionCallback
The callback invoked with the position.
errorCallback PositionErrorCallback?
The callback invoked when the position cannot be acquired.
options PositionOptions?
The options of the request.

See also

WatchPosition(PositionCallback, PositionErrorCallback?, PositionOptions?)

Geolocation.cs

Watches the position of the device (https://w3c.github.io/geolocation/#watchposition-method): the success callback is invoked with the position, then each time it changes, until Geolocation.ClearWatch is called. Returns the identifier of the watch (0 when the document is not fully active).

public int WatchPosition(PositionCallback successCallback, PositionErrorCallback? errorCallback = null, PositionOptions? options = null)

Parameters

successCallback PositionCallback
The callback invoked with the positions.
errorCallback PositionErrorCallback?
The callback invoked when a position cannot be acquired.
options PositionOptions?
The options of the requests.

Returns

int

See also