示例#1
0
        private void SetDeferrment()
        {
            if (ReportInterval == 1000 && MovementThreshold > 0)
            {
#if __IOS__
                _manager.DisallowDeferredLocationUpdates();
#endif
                if (MovementThreshold > 0)
                {
                    _manager.DistanceFilter = MovementThreshold;
                }
                else
                {
                    _manager.DistanceFilter = CLLocationDistance.FilterNone;
                }
            }
            else
            {
                if (!isDeferred
#if __IOS__
                    && _manager.AllowsBackgroundLocationUpdates
#endif
                    )
                {
                    _manager.DistanceFilter = CLLocationDistance.FilterNone;
                    double dist = MovementThreshold == 0.0 ? CLLocationDistance.MaxDistance : MovementThreshold;
#if __IOS__
                    _manager.AllowDeferredLocationUpdatesUntil(dist, ReportInterval / 1000);
#endif
                    isDeferred = true;
                }
            }
        }
示例#2
0
        private void ClManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e)
        {
            _lastLocation = DateTime.Now;

            _batteryHelper.CheckStoreBatteryLevel(TimeSpan.FromMinutes(10));

            if (!_locationsDeferred && _currentCoreLocationProfile.AllowDeferredLocationUpdates)
            {
                _clManager.AllowDeferredLocationUpdatesUntil(_currentCoreLocationProfile.DeferredLocationUpdatesDistance,
                                                             _currentCoreLocationProfile.DeferredLocationUpdatesTimeout);
            }

            foreach (CLLocation l in e.Locations)
            {
                PositionEntry p = l.ToPosition();

                p.DesiredAccuracy = _clManager.DesiredAccuracy;

                _positionCache.Distance = _currentProfile.DistanceDeltaLowTracking;
                _positionCache.Add(p);

                p.DistanceBetweenPreviousPosition = _positionCache.PreviousDistance;

                // Check if new position is around the same location using distance and time period
                if (_positionCache.Check(TimeSpan.FromSeconds(_currentProfile.TimePeriodLowTracking)))
                {
                    // Enable Low Tracking if not already enabled
                    if (_currentCoreLocationProfile != _currentProfile.LowTrackingProfile)
                    {
                        Log.Info("LowTracking");
                        MonitorCurrentRegion(p.Latitude, p.Longitude, 100, "StopRegion");
                        _currentCoreLocationProfile = _currentProfile.LowTrackingProfile;
                        ApplyCoreLocationProfile(_currentCoreLocationProfile);
                    }
                }
                else if (_currentCoreLocationProfile != _currentProfile.HighTrackingProfile)
                {
                    Log.Info("HighTracking");
                    _currentCoreLocationProfile = _currentProfile.HighTrackingProfile;
                    ApplyCoreLocationProfile(_currentCoreLocationProfile);
                }


                // Do not store location twice if it has exact same properties.
                if (!p.Equals(previousPositionEntry))
                {
                    _positionEntryRepo.Add(p);
                }

                previousPositionEntry = p;
            }
        }
示例#3
0
        public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
        {
            if (this.Request?.ThrottledInterval == null)
            {
                this.InvokeChanges(locations);
            }

            else if (!this.deferringUpdates)
            {
                manager.AllowDeferredLocationUpdatesUntil(0, this.Request.ThrottledInterval.Value.TotalMilliseconds);
                this.deferringUpdates = true;
                this.InvokeChanges(locations);
            }
        }
 public LocationManager_iOS()
 {
     _locationManager = new CLLocationManager
     {
         PausesLocationUpdatesAutomatically = false,
         AllowsBackgroundLocationUpdates    = true,
         DistanceFilter  = 15,
         Delegate        = new LocationManager_Delegate(this),
         DesiredAccuracy = CLLocation.AccuracyBest,
         ActivityType    = CLActivityType.OtherNavigation,
         ShowsBackgroundLocationIndicator = false
     };
     _locationManager.AllowDeferredLocationUpdatesUntil(10, 120);
 }
示例#5
0
        void OnLocationsUpdated(object sender, CLLocationsUpdatedEventArgs e)
        {
            foreach (CLLocation location in e.Locations)
            {
                UpdatePosition(location);
            }

            // defer future location updates if requested
            if ((listenerSettings?.DeferLocationUpdates ?? false) && !deferringUpdates && CanDeferLocationUpdate)
            {
                manager.AllowDeferredLocationUpdatesUntil(listenerSettings.DeferralDistanceMeters == null ? CLLocationDistance.MaxDistance : listenerSettings.DeferralDistanceMeters.GetValueOrDefault(),
                                                          listenerSettings.DeferralTime == null ? CLLocationManager.MaxTimeInterval : listenerSettings.DeferralTime.GetValueOrDefault().TotalSeconds);
                deferringUpdates = true;
            }
        }
示例#6
0
        static async void OnLocationsUpdated(object sender, CLLocationsUpdatedEventArgs e)
        {
            foreach (var Location in e.Locations)
            {
                await UpdatePosition(Location);
            }

            // defer future DeviceLocation updates if requested
            if ((CurrentTrackingSettings?.DeferLocationUpdates == true) && !IsDeferringUpdates && CanDeferLocationUpdate)
            {
                Manager.AllowDeferredLocationUpdatesUntil(
                    CurrentTrackingSettings.MovementThreshold,
                    CurrentTrackingSettings.DeferralTime?.TotalSeconds ?? CLLocationManager.MaxTimeInterval);

                IsDeferringUpdates = true;
            }
        }
示例#7
0
        public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
        {
            if (this.Request?.ThrottledInterval == null && this.Request?.MinimumDistance == null)
            {
                this.InvokeChanges(locations);
            }
            else if (!this.deferringUpdates)
            {
#if __IOS__
                manager.AllowDeferredLocationUpdatesUntil(
                    this.Request.MinimumDistance?.TotalMeters ?? 0,
                    this.Request.ThrottledInterval?.TotalSeconds ?? 0
                    );
#endif
                this.deferringUpdates = true;
                this.InvokeChanges(locations);
            }
        }
示例#8
0
        //SERVICE FUNCTIONS

        public void Start(int interval)
        {
            locationManager = new CLLocationManager();
            locationManager.PausesLocationUpdatesAutomatically = false;

            locationManager.RequestAlwaysAuthorization();
            locationManager.AllowsBackgroundLocationUpdates = true;

            if (CLLocationManager.LocationServicesEnabled)
            {
                //set the desired accuracy, in meters
                locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation;
                locationManager.DistanceFilter  = CLLocationDistance.FilterNone;


                var locationDelegate = new MyLocationDelegate();
                locationManager.Delegate = locationDelegate;
                locationManager.AllowDeferredLocationUpdatesUntil(CLLocationDistance.MaxDistance, interval);

                locationManager.StartUpdatingLocation();
                locationManager.StartMonitoringSignificantLocationChanges();
                //locationDelegate.StartTimer(interval);
            }
        }