/// <inheritdoc/> public void StartListening(int minTime, double minDistance, bool includeHeading = false) { if (minTime < 0) { throw new ArgumentOutOfRangeException("minTime"); } if (minDistance < 0) { throw new ArgumentOutOfRangeException("minDistance"); } if (this.IsListening) { throw new InvalidOperationException("This LocationService is already listening"); } this.listener = new GeolocationContinuousListener(this.manager, TimeSpan.FromMilliseconds(minTime), this.providers); this.listener.PositionChanged += this.OnListenerPositionChanged; this.listener.PositionError += this.OnListenerPositionError; Looper looper = Looper.MyLooper() ?? Looper.MainLooper; for (int i = 0; i < this.providers.Length; ++i) { this.manager.RequestLocationUpdates(this.providers[i], minTime, (float)minDistance, this.listener, looper); } }
/// <inheritdoc/> public void StopListening() { if (this.listener == null) { return; } this.listener.PositionChanged -= this.OnListenerPositionChanged; this.listener.PositionError -= this.OnListenerPositionError; for (int i = 0; i < this.providers.Length; ++i) { this.manager.RemoveUpdates(this.listener); } this.listener = null; }