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 GeolocationProviderRemarks
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
| Name | Description |
|---|---|
| GeolocationProvider() |
GeolocationProvider()
GeolocationProvider.cspublic GeolocationProvider()No documentation is available.
Properties
| Name | Description |
|---|---|
| Position | 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. |
Position
GeolocationProvider.csGets 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
Methods
| Name | Description |
|---|---|
| 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.csReturns 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
requestGeolocationRequest- The options of the request.
cancellationTokenCancellationToken- Canceled when the timeout of the request elapses, or the document is unloaded.
Returns
OnPositionChanged()
GeolocationProvider.csRaises 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
| Name | Description |
|---|---|
| PositionChanged | Raised when the position changes (GeolocationProvider.OnPositionChanged). |
PositionChanged
Raised when the position changes (GeolocationProvider.OnPositionChanged).
public event EventHandler? PositionChanged