Exemple #1
0
        public async Task StartListener(GpsRequest request)
        {
            if (this.IsListening)
            {
                return;
            }

            request = request ?? new GpsRequest();
            var access = await this.RequestAccess(request.UseBackground);

            access.Assert();

            var nativeRequest = LocationRequest
                                .Create()
                                .SetPriority(GetPriority(request.Priority))
                                .SetInterval(request.Interval.ToMillis());

            if (request.ThrottledInterval != null)
            {
                nativeRequest.SetFastestInterval(request.ThrottledInterval.Value.ToMillis());
            }

            await this.client.RequestLocationUpdatesAsync(
                nativeRequest,
                this.GetPendingIntent() // used for background - should switch to LocationCallback for foreground
                );

            this.IsListening = true;
        }
Exemple #2
0
        public static LocationRequest ToNative(this GpsRequest request)
        {
            var nativeRequest = LocationRequest
                                .Create()
                                .SetInterval(request.Interval.ToMillis());

            switch (request.Priority)
            {
            case GpsPriority.Low:
                nativeRequest.SetPriority(LocationRequest.PriorityLowPower);
                break;

            case GpsPriority.Highest:
                nativeRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
                break;

            case GpsPriority.Normal:
            default:
                nativeRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy);
                break;
            }

            if (request.ThrottledInterval != null)
            {
                nativeRequest.SetFastestInterval(request.ThrottledInterval.Value.ToMillis());
            }

            if (request.MinimumDistance != null)
            {
                nativeRequest.SetSmallestDisplacement((float)request.MinimumDistance.TotalMeters);
            }

            return(nativeRequest);
        }
Exemple #3
0
        /// <summary>
        /// This registers GPS services with the Shiny container as well as the delegate - you can also auto-start the listener when necessary background permissions are received
        /// </summary>
        /// <typeparam name="T">The IGpsDelegate to call</typeparam>
        /// <param name="builder">The servicecollection to configure</param>
        /// <param name="requestIfPermissionGranted">This will be called when permission is given to use GPS functionality (background permission is assumed when calling this - setting your GPS request to not use background is ignored)</param>
        /// <returns></returns>
        public static bool UseGps <T>(this IServiceCollection builder, Action <GpsRequest> requestIfPermissionGranted = null) where T : class, IGpsDelegate
        {
            if (!builder.UseGps())
            {
                return(false);
            }

            builder.TryAddStatefulSingleton <IGpsDelegate, T>(nameof(IGpsDelegate));
            if (requestIfPermissionGranted != null)
            {
                builder.RegisterPostBuildAction(async sp =>
                {
                    var request = new GpsRequest();
                    requestIfPermissionGranted(request);
                    request.UseBackground = true;

                    var mgr    = sp.GetService <IGpsManager>();
                    var access = await mgr.RequestAccess(true);
                    if (access == AccessState.Available)
                    {
                        await mgr.StartListener(request);
                    }
                });
            }
            return(true);
        }
Exemple #4
0
        public Task StartListener(GpsRequest request)
        {
            // TODO: verify background handler set
            if (this.IsListening)
            {
                throw new ArgumentException("GPS is already listening");
            }


            this.locationManager.AllowsBackgroundLocationUpdates = request.UseBackground;
            //this.locationManager.DesiredAccuracy = request
            //this.locationManager.ShouldDisplayHeadingCalibration
            //this.locationManager.ShowsBackgroundLocationIndicator
            //this.locationManager.PausesLocationUpdatesAutomatically = false;
            //this.locationManager.DistanceFilter
            //this.locationManager.DisallowDeferredLocationUpdates
            //this.locationManager.ActivityType = CLActivityType.Airborne;

            //this.locationManager.LocationUpdatesPaused
            //this.locationManager.LocationUpdatesResumed
            //this.locationManager.Failed
            //this.locationManager.UpdatedHeading

            //if (CLLocationManager.HeadingAvailable)
            //    this.locationManager.StopUpdatingHeading();
            this.locationManager.StartUpdatingLocation();
            this.IsListening = true;
            return(Task.CompletedTask);
        }
 public IObservable <AccessState> WhenAccessStatusChanged(GpsRequest request) => Observable.Create <AccessState>(ob =>
 {
     var handler = new TypedEventHandler <Geolocator, StatusChangedEventArgs>((sender, args) =>
                                                                              ob.OnNext(this.GetCurrentStatus(request))
                                                                              );
     this.geolocator.StatusChanged += null;
     return(() => this.geolocator.StatusChanged -= null);
 });
Exemple #6
0
        public Task StartListener(GpsRequest request = null)
        {
            if (!this.IsListening)
            {
                this.IsListening = true;
                request          = request ?? new GpsRequest();

                this.geolocator.ReportInterval   = Convert.ToUInt32(request.Interval.TotalMilliseconds);
                this.geolocator.PositionChanged += this.OnPositionChanged;
            }
            return(Task.CompletedTask);
        }
Exemple #7
0
        public async Task StartListener(GpsRequest request = null)
        {
            if (this.IsListening)
            {
                return;
            }

            await this.StartListenerInternal();

            this.IsListening = true;
            //mLocationRequest.setInterval(UPDATE_INTERVAL);
            //mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL);
            //mLocationRequest.setMaxWaitTime(MAX_WAIT_TIME);
        }
Exemple #8
0
        public async Task StartListener(GpsRequest request)
        {
            if (this.IsListening)
            {
                return;
            }

            request = request ?? new GpsRequest();
            var access = await this.RequestAccess(request.UseBackground);

            access.Assert();

            this.gdelegate.Request = request;
            this.locationManager.AllowsBackgroundLocationUpdates = request.UseBackground;

            if (request.ThrottledInterval != null)
            {
                this.locationManager.AllowDeferredLocationUpdatesUntil(0, request.ThrottledInterval.Value.TotalMilliseconds);
            }

            switch (request.Priority)
            {
            case GpsPriority.Highest:
                this.locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
                break;

            case GpsPriority.Normal:
                this.locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
                break;

            case GpsPriority.Low:
                this.locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters;
                break;
            }

            //this.locationManager.ShouldDisplayHeadingCalibration
            //this.locationManager.ShowsBackgroundLocationIndicator
            //this.locationManager.PausesLocationUpdatesAutomatically = false;
            //this.locationManager.DisallowDeferredLocationUpdates
            //this.locationManager.ActivityType = CLActivityType.Airborne;
            //this.locationManager.LocationUpdatesPaused
            //this.locationManager.LocationUpdatesResumed
            //this.locationManager.Failed
            //this.locationManager.UpdatedHeading
            //if (CLLocationManager.HeadingAvailable)
            //    this.locationManager.StopUpdatingHeading();
            this.locationManager.StartUpdatingLocation();
            this.IsListening = true;
        }
Exemple #9
0
        public async Task <AccessState> RequestAccess(GpsRequest request)
        {
            var bg     = request.BackgroundMode != GpsBackgroundMode.None;
            var status = await this.locationManager.RequestAccess(bg);

            if (status == AccessState.Available &&
                request.Precise &&
                UIDevice.CurrentDevice.CheckSystemVersion(14, 0) &&
                this.locationManager.AccuracyAuthorization != CLAccuracyAuthorization.FullAccuracy)
            {
                status = AccessState.Restricted;
            }

            return(status);
        }
Exemple #10
0
        public Task StartListener(GpsRequest request)
        {
            if (this.IsListening)
            {
                throw new ArgumentException("GPS is already listening");
            }

            this.IsListening = true;
            this.geolocator.PositionChanged += this.OnPositionChanged;
            //this.geolocator.DesiredAccuracy
            //this.geolocator.DesiredAccuracyInMeters
            //this.geolocator.ReportInterval


            return(Task.CompletedTask);
        }
Exemple #11
0
        public override async void OnContainerReady(IServiceProvider services)
        {
            base.OnContainerReady(services);
            if (this.requestIfPermissionGranted != null)
            {
                var mgr    = services.GetService <IGpsManager>();
                var access = await mgr.RequestAccess(true);

                if (access == AccessState.Available)
                {
                    var request = new GpsRequest();
                    this.requestIfPermissionGranted(request);
                    request.UseBackground = true;
                    await mgr.StartListener(request);
                }
            }
        }
        public AccessState GetCurrentStatus(GpsRequest request)
        {
            switch (this.geolocator.LocationStatus)
            {
            case PositionStatus.Disabled:
                return(AccessState.Disabled);

            case PositionStatus.NotAvailable:
                return(AccessState.NotSupported);

            //case PositionStatus.NotInitialized:
            case PositionStatus.Ready:
                return(AccessState.Available);

            case PositionStatus.NoData:
            case PositionStatus.Initializing:
            default:
                return(AccessState.Unknown);
            }
        }
Exemple #13
0
 public Task <AccessState> RequestAccess(GpsRequest request) => Task.FromResult(this.GetCurrentStatus(request));
Exemple #14
0
        public static async Task <AccessState> RequestAccessAndStart(this IGpsManager gps, GpsRequest request)
        {
            var access = await gps.RequestAccess(request.UseBackground);

            if (access == AccessState.Available)
            {
                await gps.StartListener(request);
            }

            return(access);
        }
Exemple #15
0
 public Task <AccessState> RequestAccess(GpsRequest request)
 => this.context.RequestLocationAccess(request.UseBackground, true, true, false);
Exemple #16
0
 public AccessState GetCurrentStatus(GpsRequest request)
 => this.context.GetCurrentLocationAccess(request.UseBackground, true, true, false);
Exemple #17
0
 public IObservable <AccessState> WhenAccessStatusChanged(GpsRequest request)
 => Observable.Interval(TimeSpan.FromSeconds(2)).Select(_ => this.GetCurrentStatus(request));
Exemple #18
0
 public AccessState GetCurrentStatus(GpsRequest request)
 => this.locationManager.GetCurrentStatus(request.BackgroundMode != GpsBackgroundMode.None);
Exemple #19
0
 public IObservable <AccessState> WhenAccessStatusChanged(GpsRequest request)
 {
     throw new NotImplementedException();
 }
Exemple #20
0
 public Task StartListener(GpsRequest request)
 {
     this.locator.Start();
     return(Task.CompletedTask);
 }
 public IObservable <AccessState> WhenAccessStatusChanged(GpsRequest request) => this.gdelegate.WhenAccessStatusChanged(request.UseBackground);
Exemple #22
0
 public AccessState GetCurrentStatus(GpsRequest request)
 {
     //this.locator.DistanceBasedLocationChanged
     throw new NotImplementedException();
 }
 public Task <AccessState> RequestAccess(GpsRequest request) => this.locationManager.RequestAccess(request.UseBackground);
 public AccessState GetCurrentStatus(GpsRequest request) => this.locationManager.GetCurrentStatus(request.UseBackground);
Exemple #25
0
 protected override Task RequestLocationUpdates(GpsRequest request) => this.Context.InvokeOnMainThreadAsync(() =>
 {
     this.listenerClient ??= LocationServices.GetFusedLocationProviderClient(this.Context.AppContext);
Exemple #26
0
 public Task <AccessState> RequestAccess(GpsRequest request)
 {
     throw new NotImplementedException();
 }