Esempio n. 1
0
 public void RemoveLocationListener(ILocationListener listener)
 {
     if (listener != null)
     {
         // remove the listener and stop location updates if necessary
         locator.PositionChanged -= listener.LocationChanged;
         registeredListeners.Remove(listener);
         if (locator.IsListening && registeredListeners.Count == 0)
         {
             locator.StopListeningAsync();
         }
     }
 }
Esempio n. 2
0
 public void Pause()
 {
     if (_crossGeolocator != null)
     {
         _crossGeolocator.StopListeningAsync();
     }
 }
Esempio n. 3
0
        public async void Listen()
        {
            position = null;

            CurrentState = State.Unknown;
            if (locator.IsListening)
            {
                await locator.StopListeningAsync();
            }

            if (!locator.IsGeolocationEnabled ||
                !locator.IsGeolocationAvailable ||
                !await locator.StartListeningAsync(TimeSpan.FromSeconds(10), 100))
            {
                CurrentState = State.Error;
            }
#if DEBUG // For emulators
            else
            {
                Position _position = await locator.GetLastKnownLocationAsync();

                if (position == null && _position != null)
                {
                    position     = _position;
                    CurrentState = State.Success;
                }
            }
#endif
        }
Esempio n. 4
0
        protected override async void OnDisappearing()
        {
            base.OnDisappearing();

            locator.PositionChanged -= Locator_PositionChanged;

            await locator.StopListeningAsync();
        }
        public async Task StopListening()
        {
            if (!locator.IsListening)
            {
                return;
            }

            await locator.StopListeningAsync();
        }
Esempio n. 6
0
        private async void StopListeningAsync()
        {
            if (!geolocatorInstance.IsListening)
            {
                return;
            }

            await geolocatorInstance.StopListeningAsync();

            geolocatorInstance.PositionChanged -= Current_PositionChanged;
        }
Esempio n. 7
0
        protected async Task CleanUp()
        {
            _lastUpdatedTime  = DateTime.MinValue;
            _previousLocation = null;

            if (_positionChangeHandler != null)
            {
                _geoLocator.PositionChanged -= _positionChangeHandler;
                _positionChangeHandler       = null;
            }
            if (_geoLocator.IsListening)
            {
                await _geoLocator.StopListeningAsync();
            }
        }
Esempio n. 8
0
        public async void AddListener(EventHandler <PositionEventArgs> listener, bool includeHeading)
        {
            if (SensusServiceHelper.Get().ObtainPermission(Permission.Location) != PermissionStatus.Granted)
            {
                throw new Exception("Could not access GPS.");
            }

            // if we're already listening, stop listening first so that the locator can be configured with
            // the most recent listening settings below.
            if (ListeningForChanges)
            {
                await _locator.StopListeningAsync();
            }

            // add new listener
            PositionChanged += listener;
            _listenerHeadings.Add(new Tuple <EventHandler <PositionEventArgs>, bool>(listener, includeHeading));

            _locator.DesiredAccuracy = SensusServiceHelper.Get().GpsDesiredAccuracyMeters;

            await _locator.StartListeningAsync(TimeSpan.FromMilliseconds(SensusServiceHelper.Get().GpsMinTimeDelayMS), SensusServiceHelper.Get().GpsMinDistanceDelayMeters, _listenerHeadings.Any(t => t.Item2), GetListenerSettings());

            SensusServiceHelper.Get().Logger.Log("GPS receiver is now listening for changes.", LoggingLevel.Normal, GetType());
        }
Esempio n. 9
0
        public async Task StopTracking()
        {
            if (!_geolocator.IsListening)
            {
                return;
            }

            await _geolocator.StopListeningAsync();

            _geolocator.PositionChanged -= PositionChanged;

            if (!Positions.Any() || Positions.Count < 2)
            {
                return;
            }

            _messagingHandler.SendMessage(Positions);
        }
Esempio n. 10
0
 public async Task StopAsync()
 {
     _geolocatorService.PositionChanged -= GeolocatorServiceOnPositionChanged;
     await _geolocatorService.StopListeningAsync();
 }
Esempio n. 11
0
 public void Stop()
 {
     _geoLocator.StopListeningAsync();
     _geoLocator.PositionChanged -= OnLocationUpdate;
 }
 protected override void OnDisappearing()
 {
     locator.StopListeningAsync();
 }
Esempio n. 13
0
 public Task <bool> StopListeningAsync()
 {
     return(bestGeolocator.StopListeningAsync());
 }
Esempio n. 14
0
 public async void StopListening()
 {
     await locator.StopListeningAsync();
 }
Esempio n. 15
0
        public Model.Position CurrentLocation()
        {
            if (_geolocator == null)
            {
                return(null);
            }
            if (!_geolocator.IsGeolocationAvailable)
            {
                return(null);
            }
            if (!_geolocator.IsGeolocationEnabled)
            {
                return(null);
            }
            if (!_geolocator.IsListening)
            {
                _geolocator.StartListeningAsync(1, 1);
            }
            if (!_geolocator.IsListening)
            {
                return(null);
            }

            if (!_geolocator.IsGeolocationAvailable)
            {
                try
                {
                    var page = new ContentPage();
                    var r    = page.DisplayAlert("Προσοχή", "Η συσκευή δεν διαθέτει GPS ή άλλη αντίστοιχη λειτουργία τοποθεσίας.", "OK");
                }
                catch (Exception ex)
                {
                    if (ex != null && !String.IsNullOrEmpty(ex.Message))
                    {
                        Mvx.Error(ex.Message);
                    }
                }

                return(null);
            }
            if (!_geolocator.IsGeolocationEnabled)
            {
                try
                {
                    var page = new ContentPage();
                    var r    = page.DisplayAlert("Προσοχή", string.Format("Η λειτουργία τοποθεσίας είναι απενεργοποιημένη.{0}Παρακαλώ ενεργοποιήστε την τοποθεσία και δοκιμάστε ξανά.", System.Environment.NewLine), "OK");
                }
                catch (Exception ex)
                {
                    if (ex != null && !String.IsNullOrEmpty(ex.Message))
                    {
                        Mvx.Error(ex.Message);
                    }
                }
                return(null);
            }
            Plugin.Geolocator.Abstractions.Position p = _geolocator.GetPositionAsync(5000).Result ?? null;
            if (!_geolocator.IsListening)
            {
                _geolocator.StopListeningAsync();
            }
            //return p;
            return(new Model.Position()
            {
                Latitude = p.Latitude, Longitude = p.Longitude
            });
        }
Esempio n. 16
0
        /// <summary>
        ///     This method ends current activity.
        /// </summary>
        public async Task StopActivityAsync()
        {
            await _geolocatorService.StopListeningAsync();

            CurrentActivity.Status = ActivityStatus.Stopped;
        }
Esempio n. 17
0
        private async void Stop(object sender, EventArgs eventArgs)
        {
            await geolocator.StopListeningAsync();

            SetValues();
        }
Esempio n. 18
0
 /// <summary>
 /// Stops the run.
 /// </summary>
 /// <returns>The run.</returns>
 public void StopRun()
 {
     IsRunning = false;
     m_locator.StopListeningAsync();
     OnRunStoped();
 }
Esempio n. 19
0
 private async void OnDisappearing(object sender, EventArgs e)
 {
     await geoLocator.StopListeningAsync();
 }