GeolocationProvider Class

The source of the positions of the device (https://w3c.github.io/geolocation/) of the browsing contexts that share a BrowsingContextOptions (BrowsingContextOptions.Geolocation), read by navigator.geolocation.getCurrentPosition() and watchPosition(). The default implementation returns GeolocationProvider.Position, set by the application (e.g. to simulate a location, as the geolocation option of Playwright). Override GeolocationProvider.GetPositionAsync to read another source (e.g. the location of the operating system), and call GeolocationProvider.OnPositionChanged when the position changes, to update the watches of the documents.

public class GeolocationProvider

Remarks

The library checks the geolocation permission and the permissions policy before reading the position, and handles the timeout and maximumAge options. A provider can be shared by several browsing contexts, and used from any thread.

Constructors

NameDescription
GeolocationProvider()

GeolocationProvider()

GeolocationProvider.cs
public GeolocationProvider()

No documentation is available.

Properties

NameDescription
PositionGets or sets the position returned by the default implementation of GeolocationProvider.GetPositionAsync, or null when the position is unavailable (POSITION_UNAVAILABLE). Setting it updates the watches of the documents.

Gets or sets the position returned by the default implementation of GeolocationProvider.GetPositionAsync, or null when the position is unavailable (POSITION_UNAVAILABLE). Setting it updates the watches of the documents.

public GeolocationReading? Position { get; set; }

Property value

GeolocationReading?

Methods

NameDescription
GetPositionAsync(GeolocationRequest, CancellationToken)Returns the position of the device, or null when it is unavailable (POSITION_UNAVAILABLE). An exception is also reported as an unavailable position. The default implementation returns GeolocationProvider.Position.
OnPositionChanged()Raises GeolocationProvider.PositionChanged, then reads the position again for the watches of the documents (watchPosition()): it is a significant change of the position. It can be called from any thread.

GetPositionAsync(GeolocationRequest, CancellationToken)

GeolocationProvider.cs

Returns the position of the device, or null when it is unavailable (POSITION_UNAVAILABLE). An exception is also reported as an unavailable position. The default implementation returns GeolocationProvider.Position.

public virtual ValueTask<GeolocationReading?> GetPositionAsync(GeolocationRequest request, CancellationToken cancellationToken)

Parameters

request GeolocationRequest
The options of the request.
cancellationToken CancellationToken
Canceled when the timeout of the request elapses, or the document is unloaded.

Returns

ValueTask<GeolocationReading?>

OnPositionChanged()

GeolocationProvider.cs

Raises GeolocationProvider.PositionChanged, then reads the position again for the watches of the documents (watchPosition()): it is a significant change of the position. It can be called from any thread.

protected void OnPositionChanged()

Events

NameDescription
PositionChangedRaised when the position changes (GeolocationProvider.OnPositionChanged).

PositionChanged

Raised when the position changes (GeolocationProvider.OnPositionChanged).

public event EventHandler? PositionChanged