/// <summary>
        /// Starts the acquisition of data from the location service.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        public void Start(LocationServiceAccuracy desiredAccuracy)
        {
            _geolocator.DesiredAccuracy         = desiredAccuracy.ToPositionAccuracy();
            _geolocator.DesiredAccuracyInMeters = null;

            _geolocator.StatusChanged   += GeolocatorStatusChanged;
            _geolocator.PositionChanged += GeolocatorPositionChanged;
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task <LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync();

            return(position.Coordinate.ToLocationServicePosition());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="maximumAge">The maximum acceptable age of cached location data.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task <LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, TimeSpan maximumAge, TimeSpan timeout)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync(maximumAge, timeout);

            return(position.Coordinate.ToLocationServicePosition());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public virtual async Task <LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, CancellationToken cancellationToken)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync()
                           .AsTask(cancellationToken);

            return(position.Coordinate.ToLocationServicePosition());
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="maximumAge">The maximum acceptable age of cached location data.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task <LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, TimeSpan maximumAge, TimeSpan timeout)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var getGeopositionAsyncTask = _geolocator.GetGeopositionAsync(maximumAge, timeout).AsTask();

            var completedTask = await Task.WhenAny(getGeopositionAsyncTask, Task.Delay((int)timeout.TotalMilliseconds + 500)).ConfigureAwait(false);

            if (completedTask != getGeopositionAsyncTask)
            {
                throw new TimeoutException();
            }

            var position = getGeopositionAsyncTask.Result;

            return(position.Coordinate.ToLocationServicePosition());
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="maximumAge">The maximum acceptable age of cached location data.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public virtual async Task<LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, TimeSpan maximumAge, TimeSpan timeout, CancellationToken cancellationToken)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var getGeopositionAsyncTask = _geolocator.GetGeopositionAsync(maximumAge, timeout)
                .AsTask(cancellationToken);

            var completedTask = await Task.WhenAny(getGeopositionAsyncTask, Task.Delay((int)timeout.TotalMilliseconds + 500, cancellationToken)).ConfigureAwait(false);

            if (completedTask != getGeopositionAsyncTask)
            {
                throw new TimeoutException();
            }

            var position = await getGeopositionAsyncTask.ConfigureAwait(false);

            return position.Coordinate.ToLocationServicePosition();
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public virtual async Task<LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, CancellationToken cancellationToken)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync()
                .AsTask(cancellationToken);

            return position.Coordinate.ToLocationServicePosition();
        }
        /// <summary>
        /// Starts the acquisition of data from the location service.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        public virtual void Start(LocationServiceAccuracy desiredAccuracy)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();
            _geolocator.DesiredAccuracyInMeters = null;

            _geolocator.StatusChanged += GeolocatorStatusChanged;
            _geolocator.PositionChanged += GeolocatorPositionChanged;
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task<LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync();

            return position.Coordinate.ToLocationServicePosition();
        }
        /// <summary>
        /// Starts an asynchronous operation to retrieve the current location.
        /// </summary>
        /// <param name="desiredAccuracy">The desired accuracy.</param>
        /// <param name="maximumAge">The maximum acceptable age of cached location data.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task<LocationServicePosition> GetPositionAsync(LocationServiceAccuracy desiredAccuracy, TimeSpan maximumAge, TimeSpan timeout)
        {
            _geolocator.DesiredAccuracy = desiredAccuracy.ToPositionAccuracy();

            var position = await _geolocator.GetGeopositionAsync(maximumAge, timeout);

            return position.Coordinate.ToLocationServicePosition();
        }