Beispiel #1
0
        public void OnLocationChanged(Location location)
        {
            _batteryHelper.CheckStoreBatteryLevel(TimeSpan.FromMinutes(10));

            positionCache.Distance = currentProfile.DistanceDeltaLowTracking;
            PositionEntry positionEntry = location.ToPositionEntry();

            positionCache.Add(positionEntry);
            Log.Trace($"GoogleApi: Location was changed {positionCache.PreviousDistance}");

            positionEntry.DistanceBetweenPreviousPosition = positionCache.PreviousDistance;

            if (positionCache.Check(TimeSpan.FromSeconds(currentProfile.TimePeriodLowTracking)))
            {
                // Enable Low Tracking if not already enabled
                if (currentRequestProfile != currentProfile.LowTrackingProfile)
                {
                    Log.Info("LowTracking");
                    currentRequestProfile = currentProfile.LowTrackingProfile;
                    RestartLocationUpdates();
                }
            }
            else if (currentRequestProfile != currentProfile.HighTrackingProfile)
            {
                Log.Info("HighTracking");
                currentRequestProfile = currentProfile.HighTrackingProfile;
                RestartLocationUpdates();
            }

            if (!positionEntry.Equals(previousPositionEntry))
            {
                positionEntryRepository.Add(positionEntry);
            }
        }
Beispiel #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;
            }
        }