Skip to content
willem640 edited this page Sep 8, 2020 · 1 revision

Geolocation.Blazor

GeolocationCoordinates GeolocationPosition
GeolocationPositionError GeolocationPositionException
GeolocationService IGeolocationService
PositionChangedEventArgs PositionErrorEventArgs
PositionOptions

GeolocationCoordinates

Represents the data from a location query

Accuracy

The accuracy of the retrieved latitude and longitude, expressed in meters

Altitude

The device's altitude

AltitudeAccuracy

The accuracy of the retrieved altitude, expressed in meters

Remarks

May be null

Heading

The direction towards which the device is facing, in clockwise degrees from true north

Remarks

May be null

Latitude

The device's latitude

Longitude

The device's longitude

Speed

The device's velocity in meters per second

Remarks

May be null

ToString

Returns a the latitude and longitude in a string

Returns

A string with a latitude and longitude

GeolocationPosition

A class that contains a timestamp and a GeolocationCoordinates object

Coords

A GeolocationCoordinates object that contains the location query result

Timestamp

The time of retrieval, unix time expressed in milliseconds

ToString

Returns a string representation of the GeolocationPosition.Coords property

Returns

A string that represents a GeolocationCoordinates object

GeolocationPositionError

A class that contains info about an encountered error while querying a device's location

Code

An error code representing the encountered error

Remarks

Three error codes are possible: | | 1 | The acquisition of the geolocation information failed because the page didn't have the permission to do it. | | 2 | The acquisition of the geolocation failed because at least one internal source of position returned an internal error. | | 3 | The time allowed to acquire the geolocation, defined by PositionOptions.Timeout information was reached before the information was obtained. |

Message

A human-readable string representation of the error

ToString

Returns the GeolocationPositionError.Message property

Returns

A human-readable string

GeolocationPositionException

Similar to the GeolocationPositionError class, but used as an exception

Constructor

Initializes a new instance of the GeolocationPositionException class

Constructor(info, context)

Initializes a new instance of the GeolocationPositionException class

Name Description
info System.Runtime.Serialization.SerializationInfo
The System.Runtime.Serialization.SerializationInfo object that holds the serialized object data about the exception being thrown
context System.Runtime.Serialization.StreamingContext
The System.Runtime.Serialization.StreamingContext that holds contextual information about the source or destination

Constructor(message, innerException)

Initializes a new instance of the GeolocationPositionException class

Name Description
message System.String
The exception message
innerException System.Exception
The inner exception

Constructor(message)

Initializes a new instance of the GeolocationPositionException class

Name Description
message System.String
The exception message

Code

GeolocationService

The main entry point of the API

Constructor(jSRuntime)

Initializes a new instance of the GeolocationService class, and requests objects through dependency injection

Name Description
jSRuntime Microsoft.JSInterop.IJSRuntime
An Microsoft.JSInterop.IJSRuntime object

AttachEvents

ClearWatchAsync(System.Int64)

Finalize

Destructs the object and disposes of remaining System.IDisposables

GetCurrentPositionAsync(Geolocation.Blazor.PositionOptions)

GetCurrentPositionAsync(System.Action{Geolocation.Blazor.GeolocationPosition},System.Action{Geolocation.Blazor.GeolocationPositionError},Geolocation.Blazor.PositionOptions)

InjectJSHelper

Creates a JavaScript object with helper methods

OnPositionChanged(eventArgs)

A method that is when GeolocationService.PositionChanged should fire

Name Description
eventArgs Geolocation.Blazor.PositionChangedEventArgs
A PositionChangedEventArgs object representing the event arguments

OnPositionError(eventArgs)

A method that is when GeolocationService.PositionError should fire

Name Description
eventArgs Geolocation.Blazor.PositionErrorEventArgs
A PositionErrorEventArgs object representing the event arguments

PositionChanged

PositionError

WatchPositionAsync(System.Action{Geolocation.Blazor.GeolocationPosition},System.Action{Geolocation.Blazor.GeolocationPositionError},Geolocation.Blazor.PositionOptions)

IGeolocationService

An interface that defines a Geolocation Service

AttachEvents

A method that can be called to attach the IGeolocationService.PositionChanged and IGeolocationService.PositionError events

ClearWatchAsync(id)

A function that unregisters a handler registered with IGeolocationService.WatchPositionAsync(System.Action{Geolocation.Blazor.GeolocationPosition},System.Action{Geolocation.Blazor.GeolocationPositionError},Geolocation.Blazor.PositionOptions)

Name Description
id System.Int64
A unique id, acquired from IGeolocationService.WatchPositionAsync(System.Action{Geolocation.Blazor.GeolocationPosition},System.Action{Geolocation.Blazor.GeolocationPositionError},Geolocation.Blazor.PositionOptions)

GetCurrentPositionAsync(options)

Gets the device's position

Name Description
options Geolocation.Blazor.PositionOptions
Optional PositionOptions object

Returns

A GeolocationPosition object with the device's current location and the retrieval timestamp

GetCurrentPositionAsync(success, error, options)

Takes two delegates that will be called once, either when the location is acquired, or when there is an error

Remarks

When there is an error, the success delegate will not be called

Name Description
success System.Action{Geolocation.Blazor.GeolocationPosition}
A delegate that takes a GeolocationPosition object, and returns nothing
error System.Action{Geolocation.Blazor.GeolocationPositionError}
A delegate that takes a GeolocationPositionError object, and returns nothing
options Geolocation.Blazor.PositionOptions
An optional PositionOptions object

PositionChanged

An event that is triggered when the device's position changes

Remarks

For this event to fire at all, IGeolocationService.AttachEvents will first need to be called

PositionError

An event that is triggered when an error is encountered querying the device's position

Remarks

WatchPositionAsync(success, error, options)

Registers two delegates that are called every time the browser detects a change in the device's location

Remarks

May be called more than once with the same location

Name Description
success System.Action{Geolocation.Blazor.GeolocationPosition}
A delegate that takes a GeolocationPosition object, and returns nothing
error System.Action{Geolocation.Blazor.GeolocationPositionError}
A delegate that takes a GeolocationPositionError object, and returns nothing
options Geolocation.Blazor.PositionOptions
An optional PositionOptions object

Returns

A unique identifier that may be used in IGeolocationService.ClearWatchAsync(System.Int64)

PositionChangedEventArgs

A class that wraps a GeolocationPosition for use in events

Position

The GeolocationPosition that is wrapped

PositionErrorEventArgs

Wraps a GeolocationPositionError object for use in events

Error

The GeolocationPositionError object that is wrapped

PositionOptions

A class that contains options for retrieving locations

EnableHighAccuracy

Indicates whether to sacrifice performance for accuracy

Remarks

May result in longer response times

MaximumAge

The oldest a cached position may be

Timeout

The longest time the device may take to retrieve the location, in milliseconds

ToString

Returns a string representation of the options

Returns

A human-readable string