public void Start(LocationConfigBase config, Action <GeoLocation> locationChanged, Action <Exception> locationError) { System.Diagnostics.Debug.WriteLine("Starting location service..."); _LocationChanged = locationChanged; _LocationError = locationError; _Config = config; try { string provider = (config.Accuracy == LocationAccuracy.Course) ? LocationManager.NetworkProvider : LocationManager.GpsProvider; if (!_Manager.IsProviderEnabled(provider)) { State = LocationServiceState.Error; locationError?.Invoke(new Exception(string.Format("The requested location provider ({0}) is not enabled.", provider))); return; } // register for location updates _Manager.RequestLocationUpdates(provider, config.UpdateInterval, config.MovementThreshold, this); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error staring navigation service\r\n{0}", ex.Message); locationError?.Invoke(ex); State = LocationServiceState.Error; } }
public LocationService(LocationConfig config) { _Config = config; State = LocationServiceState.None; _Manager = (LocationManager)config.AppContext.GetSystemService(Context.LocationService); }
public void Start(LocationConfigBase config, Action <GeoLocation> locationChanged, Action <Exception> locationError) { try { if (_Manager == null) { _Manager = new CLLocationManager(); } _LocationChanged = locationChanged; _LocationError = locationError; System.Diagnostics.Debug.WriteLine("Starting location service"); // register app with this service ALWAYS if (_Manager.RespondsToSelector(new Selector("requestAlwaysAuthorization"))) { _Manager.RequestAlwaysAuthorization(); } if (!CLLocationManager.LocationServicesEnabled) { System.Diagnostics.Debug.WriteLine("Location services are disabled. Requesting permission."); if (!CLLocationManager.LocationServicesEnabled) { System.Diagnostics.Debug.WriteLine("Location services are still disabled."); State = LocationServiceState.Disabled; if (_LocationError != null) { _LocationError(new Exception("Location services are disabled.")); } return; } } _Manager.LocationsUpdated += _Manager_LocationsUpdated; _Manager.UpdatedLocation += _Manager_UpdatedLocation; _Manager.DesiredAccuracy = config.MovementThreshold; _Manager.DistanceFilter = config.MovementThreshold; _Manager.StartUpdatingLocation(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error starting location services\r\n{0}", ex.Message); State = LocationServiceState.Error; if (_LocationError != null) { _LocationError(ex); } } }
public LocationPlayService(LocationConfig config) { _Config = config; // check if play services is enabled if (_Config.CheckEnabled == null) { throw new Exception("Unable to check whether play services are available. Make sure you have a CheckEnabled Action."); } State = (_Config.CheckEnabled()) ? LocationServiceState.Enabled : LocationServiceState.Disabled; _Client = LocationServices.GetFusedLocationProviderClient(config.AppContext); if (_Client == null) { State = LocationServiceState.Disabled; } }
public void Start(LocationConfigBase config, Action <GeoLocation> locationChanged, Action <Exception> locationError) { _LocationChanged = locationChanged; _LocationError = locationError; LocationRequest request = new LocationRequest().SetPriority((config.Accuracy == LocationAccuracy.Course) ? LocationRequest.PriorityLowPower : LocationRequest.PriorityHighAccuracy); if (config.MovementThreshold > 0) { request.SetSmallestDisplacement(config.MovementThreshold); } else { request.SetInterval(config.UpdateInterval).SetFastestInterval(config.UpdateInterval); } Task.Run(async() => await _Client.RequestLocationUpdatesAsync(request, this)); }