コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }