/// <inheritdoc/> /// <exception cref="GeolocationPositionException">Thrown when an error is encountered in the browser API</exception> public async Task <GeolocationPosition> GetCurrentPositionAsync(PositionOptions options = null) { var tcs = new TaskCompletionSource <GeolocationPosition>(); await GetCurrentPositionAsync((GeolocationPosition pos) => tcs.SetResult(pos), (GeolocationPositionError err) => tcs.SetException(new GeolocationPositionException(err)), options); return(await tcs.Task); }
/// <inheritdoc/> public async Task <long> WatchPositionAsync(Action <GeolocationPosition> success, Action <GeolocationPositionError> error = null, PositionOptions options = null) { var successJsAction = new JSAction <GeolocationPosition>(success); var errorJsAction = new JSAction <GeolocationPositionError>(error); var successRef = DotNetObjectReference.Create(successJsAction); var errorRef = DotNetObjectReference.Create(errorJsAction); await InjectJSHelper(); long id = await jsRuntime.InvokeAsync <long>("GeolocationBlazor.WatchPosition", successRef, errorRef, options).AsTask(); disposablesByWatchId.Add(id, new List <IDisposable> { successRef, errorRef }); return(id); }
/// <inheritdoc/> public async Task GetCurrentPositionAsync(Action <GeolocationPosition> success, Action <GeolocationPositionError> error = null, PositionOptions options = null) { var successJsAction = new JSAction <GeolocationPosition>(success); var errorJsAction = new JSAction <GeolocationPositionError>(error); var successRef = DotNetObjectReference.Create(successJsAction); var errorRef = DotNetObjectReference.Create(errorJsAction); await InjectJSHelper(); await jsRuntime.InvokeVoidAsync("GeolocationBlazor.GetCurrentPosition", successRef, errorRef, options); }