示例#1
0
        /// <summary>
        /// Gets the last known and most accurate location.
        /// This is usually cached and best to display first before querying for full position.
        /// </summary>
        /// <returns>Best and most recent location or null if none found</returns>
        public async Task <Position> GetLastKnownLocationAsync()
        {
            var hasPermission = await CheckWhenInUsePermission();

            if (!hasPermission)
            {
                throw new GeolocationException(GeolocationError.Unauthorized);
            }

            Location bestLocation = null;

            foreach (var provider in Providers)
            {
                var location = Manager.GetLastKnownLocation(provider);
                if (location != null && GeolocationUtils.IsBetterLocation(location, bestLocation))
                {
                    bestLocation = location;
                }
            }

            return(bestLocation?.ToPosition());
        }
示例#2
0
 void Finish(Android.Locations.Location location)
 {
     _finishedCallback?.Invoke();
     _tcs.TrySetResult(location.ToPosition());
 }