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); } }
protected async Task <bool> StartGeolocatorAsync() { if (!Geolocator.IsGeolocationAvailable) { return(false); } if (Geolocator.IsListening) { return(true); } Geolocator.PositionChanged += GeolocatorOnPositionChanged; return(await Geolocator.StartListeningAsync(TimeSpan.FromMilliseconds(100), 1 /* Meters */)); }
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"); } }