Exemple #1
0
        /// <inheritdoc />
        public Task <GeolocationAccessStatus> RequestAccessAsync()
        {
            var status = this.locationProviders.Any(this.locationManager.IsProviderEnabled)
                             ? GeolocationAccessStatus.Allowed
                             : GeolocationAccessStatus.Denied;

            if (this.locationListener == null && status == GeolocationAccessStatus.Allowed)
            {
                this.locationListener = new GeolocatorLocationListener(
                    this.locationManager,
                    this.ReportInterval,
                    this.locationProviders);

                this.locationListener.PositionChanged += this.LocationListener_PositionChanged;
                this.locationListener.StatusChanged   += this.LocationListener_StatusChanged;

                var looperThread = Looper.MyLooper() ?? Looper.MainLooper;
                foreach (var provider in this.locationProviders)
                {
                    this.locationManager.RequestLocationUpdates(
                        provider,
                        this.reportInterval,
                        this.DesiredAccuracyInMeters,
                        this.locationListener,
                        looperThread);
                }
            }

            return(Task.FromResult(status));
        }
Exemple #2
0
 private void LocationListener_PositionChanged(GeolocatorLocationListener sender, PositionChangedEventArgs args)
 {
     lock (this.obj)
     {
         this.LastKnownPosition = args.Position;
         this.PositionChanged?.Invoke(this, args);
     }
 }
Exemple #3
0
 private void LocationListener_StatusChanged(GeolocatorLocationListener sender, StatusChangedEventArgs args)
 {
     this.LocationStatus = args.Status;
     this.StatusChanged?.Invoke(this, args);
 }