Ejemplo n.º 1
0
        /// <summary>
        ///     Start listening to location changes
        /// </summary>
        /// <param name="minTime">Minimum interval in milliseconds</param>
        /// <param name="minDistance">Minimum distance in meters</param>
        /// <param name="includeHeading">Include heading information</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        ///     minTime
        ///     or
        ///     minDistance
        /// </exception>
        /// <exception cref="System.InvalidOperationException">This Geolocator is already listening</exception>
        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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Stop listening to location changes
        /// </summary>
        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;
        }