Exemplo n.º 1
0
        public void StartListening(uint minTime, double minDistance, bool includeHeading)
        {
            if (minTime < 0)
            {
                throw new ArgumentOutOfRangeException("minTime");
            }
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (IsListening)
            {
                throw new InvalidOperationException("This Geolocator is already listening");
            }

            _listener = new GeolocationContinuousListener(_manager, TimeSpan.FromMilliseconds(minTime), _providers);
            _listener.PositionChanged += OnListenerPositionChanged;
            _listener.PositionError   += OnListenerPositionError;

            var looper = Looper.MyLooper() ?? Looper.MainLooper;

            for (var i = 0; i < _providers.Length; ++i)
            {
                _manager.RequestLocationUpdates(_providers[i], minTime, (float)minDistance, _listener, looper);
            }
        }
Exemplo n.º 2
0
        public void StopListening()
        {
            if (_listener == null)
            {
                return;
            }

            _listener.PositionChanged -= OnListenerPositionChanged;
            _listener.PositionError   -= OnListenerPositionError;

            for (var i = 0; i < _providers.Length; ++i)
            {
                _manager.RemoveUpdates(_listener);
            }

            _listener = null;
        }