public void OnLocationChanged(Location location)
        {
            if (location.Accuracy <= _DesiredAccuracy)
            {
                Finish(location);
                return;
            }

            lock (_LocationSync)
            {
                if (GeolocationUtils.IsBetterLocation(location, _BestLocation))
                {
                    _BestLocation = location;
                }
            }
        }
        public async Task <Position> GetLastKnownLocationAsync()
        {
            var hasPermission = await CheckPermissions();

            if (!hasPermission)
            {
                return(null);
            }

            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());
        }
        public GeolocationSingleListener(LocationManager manager, float desiredAccuracy, int timeout, IEnumerable <string> activeProviders, Action finishedCallback)
        {
            _DesiredAccuracy  = desiredAccuracy;
            _FinishedCallback = finishedCallback;

            var activeProviderStrings = activeProviders as string[] ?? activeProviders.ToArray();

            _ActiveProviders = new HashSet <string>(activeProviderStrings);

            foreach (var provider in activeProviderStrings)
            {
                var location = manager.GetLastKnownLocation(provider);
                if (location != null && GeolocationUtils.IsBetterLocation(location, _BestLocation))
                {
                    _BestLocation = location;
                }
            }


            if (timeout != Timeout.Infinite)
            {
                new Timer(TimesUp, null, timeout, 0);
            }
        }