コード例 #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();
         }
     }
 }
コード例 #2
0
 public void Pause()
 {
     if (_crossGeolocator != null)
     {
         _crossGeolocator.StopListeningAsync();
     }
 }
コード例 #3
0
ファイル: GeoLocator.cs プロジェクト: Haus4/NeCo
        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
        }
コード例 #4
0
        protected override async void OnDisappearing()
        {
            base.OnDisappearing();

            locator.PositionChanged -= Locator_PositionChanged;

            await locator.StopListeningAsync();
        }
コード例 #5
0
        public async Task StopListening()
        {
            if (!locator.IsListening)
            {
                return;
            }

            await locator.StopListeningAsync();
        }
コード例 #6
0
        private async void StopListeningAsync()
        {
            if (!geolocatorInstance.IsListening)
            {
                return;
            }

            await geolocatorInstance.StopListeningAsync();

            geolocatorInstance.PositionChanged -= Current_PositionChanged;
        }
コード例 #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();
            }
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #10
0
 public async Task StopAsync()
 {
     _geolocatorService.PositionChanged -= GeolocatorServiceOnPositionChanged;
     await _geolocatorService.StopListeningAsync();
 }
コード例 #11
0
 public void Stop()
 {
     _geoLocator.StopListeningAsync();
     _geoLocator.PositionChanged -= OnLocationUpdate;
 }
コード例 #12
0
 protected override void OnDisappearing()
 {
     locator.StopListeningAsync();
 }
コード例 #13
0
 public Task <bool> StopListeningAsync()
 {
     return(bestGeolocator.StopListeningAsync());
 }
コード例 #14
0
 public async void StopListening()
 {
     await locator.StopListeningAsync();
 }
コード例 #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
            });
        }
コード例 #16
0
        /// <summary>
        ///     This method ends current activity.
        /// </summary>
        public async Task StopActivityAsync()
        {
            await _geolocatorService.StopListeningAsync();

            CurrentActivity.Status = ActivityStatus.Stopped;
        }
コード例 #17
0
        private async void Stop(object sender, EventArgs eventArgs)
        {
            await geolocator.StopListeningAsync();

            SetValues();
        }
コード例 #18
0
 /// <summary>
 /// Stops the run.
 /// </summary>
 /// <returns>The run.</returns>
 public void StopRun()
 {
     IsRunning = false;
     m_locator.StopListeningAsync();
     OnRunStoped();
 }
コード例 #19
0
ファイル: MapViewModel.cs プロジェクト: NazarHomeniuk/Siren
 private async void OnDisappearing(object sender, EventArgs e)
 {
     await geoLocator.StopListeningAsync();
 }