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; } }
public void StartLocationUpdates() { Authorize(); bool invalidPermissions = CLLocationManager.Status != CLAuthorizationStatus.AuthorizedAlways; bool trackingAllowed = Settings.Current.Tracking; if (invalidPermissions || !trackingAllowed) { return; } _currentCoreLocationProfile = _currentProfile.HighTrackingProfile; _clManager.StartUpdatingLocation(); //_significantLocationManager.StartMonitoringSignificantLocationChanges(); IsListening = true; }
private void ApplyCoreLocationProfile(CoreLocationProfile profile) { _clManager.DesiredAccuracy = profile.DesiredAccuracy; _clManager.DistanceFilter = profile.DistanceFilter; _clManager.AllowsBackgroundLocationUpdates = profile.AllowBackgroundLocationUpdates; _clManager.PausesLocationUpdatesAutomatically = profile.PauseLocationUpdatesAutomatically; //if (profile.MonitorSignificantChanges) //{ // _clManager.StartMonitoringSignificantLocationChanges(); //} //else //{ // _clManager.StopMonitoringSignificantLocationChanges(); //} if (_locationsDeferred && !profile.AllowDeferredLocationUpdates) { _clManager.DisallowDeferredLocationUpdates(); _locationsDeferred = false; } }
void _clManager_RegionLeft(object sender, CLRegionEventArgs e) { _currentCoreLocationProfile = _currentProfile.HighTrackingProfile; ApplyCoreLocationProfile(_currentCoreLocationProfile); }