示例#1
0
        public async Task ExecuteStartTrackingTripCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                if (Geolocator.IsListening)
                {
                    await Geolocator.StopListeningAsync();
                }

                if (Geolocator.IsGeolocationAvailable && (CrossDeviceInfo.Current.Platform == Plugin.DeviceInfo.Abstractions.Platform.iOS || Geolocator.IsGeolocationEnabled))
                {
                    //25 Geolocator.AllowsBackgroundUpdates = true;
                    Geolocator.DesiredAccuracy = 25;

                    Geolocator.PositionChanged += Geolocator_PositionChanged;
                    //every 3 second, 5 meters
                    await Geolocator.StartListeningAsync(TimeSpan.FromSeconds(3), 5);
                }
                else
                {
                    Acr.UserDialogs.UserDialogs.Instance.Alert(
                        "Please ensure that geolocation is enabled and permissions are allowed for MyDriving to start a recording.",
                        "Geolocation Disabled", "OK");
                }
            }
            catch (Exception ex)
            {
                //26 Logger.Instance.Report(ex);
            }
        }
示例#2
0
        protected async Task <bool> StopGeolocatorIfUnusedAsync()
        {
            if (TargetPositionObservers.Any())
            {
                return(true);
            }

            Geolocator.PositionChanged -= GeolocatorOnPositionChanged;

            if (Geolocator.IsListening)
            {
                return(await Geolocator.StopListeningAsync());
            }

            return(true);
        }
示例#3
0
        public async Task StopLocationUpdates()
        {
            if (_isRunning)
            {
                _forceSendTimer.Stop();

                if (await Geolocator.StopListeningAsync())
                {
                    Geolocator.PositionChanged -= Geolocator_PositionChanged;
                    _isRunning = false;

                    _preferences.Set(UserSettingsKeys.LiveLocationSharingEnabled, false);
                    _loggingService.Trace("Executing LocationManager.StopLocationUpdates");
                }
            }
        }
示例#4
0
        public async Task ExecuteStopTrackingTripCommandAsync()
        {
            if (IsBusy || !IsRecording)
            {
                return;
            }

            try
            {
                //Unsubscribe because we were recording and it is alright
                Geolocator.PositionChanged -= Geolocator_PositionChanged;
                await Geolocator.StopListeningAsync();
            }
            catch (Exception ex)
            {
                //27 Logger.Instance.Report(ex);
            }
        }
示例#5
0
        public async Task StartLocationUpdates()
        {
            if (_isRunning)
            {
                return;
            }

            if (await EnsureHasPermissions() is false)
            {
                _loggingService.Trace("Can't Execute LocationManager.StartLocationUpdates, no permissions");

                if (_preferences.Get(UserSettingsKeys.ShowDebugToasts, false) is true)
                {
                    _userDialogs.Toast("Can't start location sharing, no permissions");
                }

                return;
            }

            _loggingService.Trace("Executing LocationManager.StartLocationUpdates");

            try
            {
                if (_preferences.Get(UserSettingsKeys.ShowDebugToasts, false) is true)
                {
                    _userDialogs.Toast("Live Location Sharing has started");
                }

                _isRunning = true;

                if (Geolocator.IsListening)
                {
                    await Geolocator.StopListeningAsync();
                }

                if (Geolocator.IsGeolocationAvailable && Geolocator.IsGeolocationEnabled)
                {
                    Geolocator.DesiredAccuracy  = 5;
                    Geolocator.PositionChanged += Geolocator_PositionChanged;

                    _forceSendTimer.Elapsed += async(sender, args) =>
                    {
                        if (!_isRunning)
                        {
                            _forceSendTimer.Stop();
                            return;
                        }

                        // Ensure it updates at least every 60 seconds
                        if (DateTime.Now - _lastUpdateTime < TimeSpan.FromSeconds(MinimalUpdateTimespan))
                        {
                            return;
                        }

                        var lastKnownLocation = await Geolocator.GetLastKnownLocationAsync();

                        if (lastKnownLocation != null)
                        {
                            try
                            {
                                var position = new Position(lastKnownLocation.Latitude, lastKnownLocation.Longitude);
                                await UpdateLocation(position);
                            }
                            catch (Exception ex)
                            {
                                _loggingService.Error(ex, "Error Executing LocationManager._forceSendTimer.Elapsed");
                            }
                        }
                    };


                    //every 5 second, 5 meters
                    await Geolocator.StartListeningAsync(TimeSpan.FromSeconds(5), 5);

                    _forceSendTimer.Start();
                }
                else
                {
                    Mvx.IoCProvider.Resolve <IUserDialogs>().Alert(
                        "Please ensure that geolocation is enabled and permissions are allowed for Wasabee to start sharing your location.",
                        "Geolocation Disabled", "OK");
                }
            }
            catch (Exception ex)
            {
                _loggingService.Error(ex, "Error Executing LocationManager.StartLocationUpdates");
            }
        }