public async Task StopAsync() { if (_client != null) { await _client.RemoveLocationUpdatesAsync(this); } }
public async Task StopRequestionLocationUpdates() { if (_isRequestingLocationUpdates) { _isRequestingLocationUpdates = false; await _fusedLocationProviderClient.RemoveLocationUpdatesAsync(_locationCallback); } }
private async void StopButtonClicked(object sender, EventArgs e) { try { # if SHOW_BUG await #endif _fusedLocationClient.RemoveLocationUpdatesAsync(_locationCallback); Toast.MakeText(this, "Location Updates Ended", ToastLength.Long).Show(); }
private async void StopButtonClicked(object sender, EventArgs e) { try { await _fusedLocationClient.RemoveLocationUpdatesAsync(_locationCallback); Toast.MakeText(this, "Location Updates Ended", ToastLength.Long).Show(); } catch (Exception exception) { Console.WriteLine(exception); } }
async void StopRequestionLocationUpdates() { latitude2.Text = string.Empty; longitude2.Text = string.Empty; provider2.Text = string.Empty; requestLocationUpdatesButton.SetText(Resource.String.request_location_button_text); if (isRequestingLocationUpdates) { await fusedLocationProviderClient.RemoveLocationUpdatesAsync(locationCallback); } }
protected override async void OnPause() { // Unsubscribe from the event locationCallback.LocationResult -= LocationCallback_LocationResult; // TODO: We should await this call but there appears to be a bug // in Google Play Services where the first time removeLocationUpdates is called, // the returned Android.Gms.Tasks.Task never actually completes, even though // location updates do seem to be removed and stop happening. // For now we'll just fire and forget as a workaround. fusedClient.RemoveLocationUpdatesAsync(locationCallback); base.OnPause(); }
void StopLocationUpdates() { if (!requestingUpdates) { return; } fusedLocationClient.RemoveLocationUpdatesAsync(locationCallback).ContinueWith((r) => { //nothing to do here }, TaskScheduler.FromCurrentSynchronizationContext()); locationCallback.LocationUpdated -= OnLocationResult; requestingUpdates = false; UpdateUI(); }
private async void OnClickRemoveLocationUpdates(object sender, EventArgs eventArgs) { string Tag = "RemoveLocationUpdates"; var task = fusedLocationProviderClient.RemoveLocationUpdatesAsync(locationCallback); try { await task; if (task.IsCompleted) { log.Info(Tag, "RemoveLocationUpdates with callback succeeded."); } else { log.Error(Tag, $"RemoveLocationUpdates with callback failed:{task.Exception.Message}"); } } catch (Exception e) { log.Error(Tag, $"RemoveLocationUpdates with callback failed:{e.Message}"); } }
protected override IObservable <LocationRecorded> CreateStartLocationUpdates() { return(Observable.Create <LocationRecorded>(subj => { CompositeDisposable disp = new CompositeDisposable(); try { if (mLocationRequest == null) { mLocationRequest = LocationRequest.Create(); mLocationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy); mLocationRequest.SetInterval(10000); mLocationRequest.SetFastestInterval(5000); } var locationResults = Observable.FromEventPattern <LocationCallbackResultEventArgs> ( x => _myCallback.LocationResult += x, x => _myCallback.LocationResult -= x ) .SelectMany(lu => lu.EventArgs.Result.Locations) .Select(lu => PositionFactory(lu)) .Where(lu => lu != null) .StartWith((LocationRecorded)null) .Catch((Exception exc) => { return Observable.Throw <LocationRecorded>(exc); }); var removeLocationUpdates = Observable.Create <Unit>(subs => { return mFusedLocationClient .RemoveLocationUpdatesAsync(_myCallback) .ToObservable() .CatchAndLog(ExceptionHandling, Unit.Default) .Subscribe(subs); }) .SubscribeOn(Scheduler.Dispatcher); // GetLocationAvailabilityAsync() throws an ApiException // if google play services aren't available // so I don't currently see the point of checking that before requesting location updates // since I feel like they will achieve the same thing at this point // need to investigate where there might be divergent behavior between the two Func <IObservable <bool> > requestUpdates = null; requestUpdates = () => // using from async to ensure it's lazy Observable.FromAsync(() => mFusedLocationClient .RequestLocationUpdatesAsync(mLocationRequest, _myCallback) ) .Select(_ => true) .Do(_ => { // successfully requesting updates so setup remove on unsubscribe. // only want to wire this up if requesting updates is successful Disposable.Create(() => { removeLocationUpdates .Subscribe(); }) .DisposeWith(disp); }) // error trying to request updates .Catch((ApiException api) => { var activationException = new LocationActivationException ( ActivationFailedReasons.CheckExceptionOnPlatform, api ); ExceptionHandling .LogException(activationException); // wait for a change in location availibility to occur return Observable.FromEventPattern <LocationCallbackAvailabilityEventArgs> ( x => _myCallback.LocationAvailability += x, x => _myCallback.LocationAvailability -= x ) .Select(changed => changed.EventArgs.Availability.IsLocationAvailable) .Log("Availability") .Where(x => x) .Take(1) .SelectMany(_ => requestUpdates()); }) // unknown exception occurred :-( .Catch((Exception exc) => { return Observable.Throw <bool>(exc); }) .StartWith(false); Observable.CombineLatest( locationResults, requestUpdates(), (result, requestUpdatesActive) => { IsListeningForChangesImperative = true; if (!requestUpdatesActive) { return Observable.Empty <LocationRecorded>(); } if (result == null) { return Observable.Empty <LocationRecorded>(); } return Observable.Return(result); }) .SelectMany(x => x) .Subscribe(subj) .DisposeWith(disp); Disposable.Create(() => { IsListeningForChangesImperative = false; }) .DisposeWith(disp); return disp; } catch (Exception exc) { subj.OnError(exc); disp.Dispose(); } return Disposable.Empty; } ) .SubscribeOn(Scheduler.Dispatcher)); }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your fragment here if (Arguments != null) { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader( new System.IO.StringReader(Arguments.GetString("data", null)))) { location = LocationData.FromJson(jsonTextReader); } if (location != null && wLoader == null) { wLoader = new WeatherDataLoader(location, this, this); } } if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS) { mFusedLocationClient = new FusedLocationProviderClient(Activity); mLocCallback = new LocationCallback(); mLocCallback.LocationResult += async(sender, e) => { mLocation = e.Result.LastLocation; if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); } await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback); }; } else { mLocListnr = new Droid.Helpers.LocationListener(); mLocListnr.LocationChanged += async(Android.Locations.Location location) => { if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); } }; } dataReceiver = new LocalBroadcastReceiver(); dataReceiver.BroadcastReceived += async(context, intent) => { if (WearableHelper.LocationPath.Equals(intent?.Action) || WearableHelper.WeatherPath.Equals(intent?.Action)) { if (WearableHelper.WeatherPath.Equals(intent.Action) || (!loaded && location != null)) { if (timer.Enabled) { timer.Stop(); } // We got all our data; now load the weather wLoader = new WeatherDataLoader(location, this, this); await wLoader.ForceLoadSavedWeatherData(); } if (WearableHelper.LocationPath.Equals(intent.Action)) { // We got the location data location = Settings.HomeData; loaded = false; } } else if (WearableHelper.ErrorPath.Equals(intent?.Action)) { // An error occurred; cancel the sync operation await CancelDataSync(); } else if (WearableHelper.IsSetupPath.Equals(intent?.Action)) { if (Settings.DataSync != WearableDataSync.Off) { bool isDeviceSetup = intent.GetBooleanExtra(WearableDataListenerService.EXTRA_DEVICESETUPSTATUS, false); var connStatus = (WearConnectionStatus)intent.GetIntExtra(WearableDataListenerService.EXTRA_CONNECTIONSTATUS, 0); if (isDeviceSetup && connStatus == WearConnectionStatus.Connected) { // Device is setup and connected; proceed with sync Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_REQUESTLOCATIONUPDATE)); Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_REQUESTWEATHERUPDATE)); ResetTimer(); } else { // Device is not connected; cancel sync await CancelDataSync(); } } } }; loaded = true; }
public async Task CancelLocationUpdates() { await _locationProvider.RemoveLocationUpdatesAsync(_locationCallback); }
public async Task StopUpdatingLocationAsync() { await _fusedLocationProviderClient.RemoveLocationUpdatesAsync(this); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.activity_setup); cts = new CancellationTokenSource(); wm = WeatherData.WeatherManager.GetInstance(); // Set default API to HERE // if a valid API key hasn't been entered yet if (wm.KeyRequired && !Settings.KeyVerified) { Settings.API = WeatherData.WeatherAPI.Here; wm.UpdateAPI(); if (String.IsNullOrWhiteSpace(wm.GetAPIKey())) { // If (internal) key doesn't exist, fallback to Yahoo Settings.API = WeatherData.WeatherAPI.Yahoo; wm.UpdateAPI(); Settings.UsePersonalKey = true; Settings.KeyVerified = false; } else { // If key exists, go ahead Settings.UsePersonalKey = false; Settings.KeyVerified = true; } } // Controls searchButton = FindViewById <FloatingActionButton>(Resource.Id.search_button); searchButton.Click += (sender, e) => { FragmentManager.BeginTransaction() .Replace(Resource.Id.search_fragment_container, new LocationSearchFragment()) .Commit(); mWearableActionDrawer.Controller.CloseDrawer(); }; locationButton = FindViewById <FloatingActionButton>(Resource.Id.location_button); locationButton.Click += async(sender, e) => { await FetchGeoLocation(); }; mWearableActionDrawer = FindViewById <WearableActionDrawerView>(Resource.Id.bottom_action_drawer); mWearableActionDrawer.SetOnMenuItemClickListener(this); mWearableActionDrawer.LockedWhenClosed = true; mWearableActionDrawer.Controller.PeekDrawer(); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); progressBar.Visibility = ViewStates.Gone; // Location client if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS) { mFusedLocationClient = new FusedLocationProviderClient(this); mLocCallback = new LocationCallback(); mLocCallback.LocationResult += async(sender, e) => { if (e.Result == null) { mLocation = null; } else { mLocation = e.Result.LastLocation; } if (mLocation == null) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } else { await FetchGeoLocation(); } await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback); }; mLocCallback.LocationAvailability += async(sender, e) => { await mFusedLocationClient.FlushLocationsAsync(); if (!e.Availability.IsLocationAvailable) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } }; } else { mLocListnr = new Droid.Helpers.LocationListener(); mLocListnr.LocationChanged += async(Location location) => { mLocation = location; await FetchGeoLocation(); }; } }
/* * Stop updating location information */ public void StopLocationUpdates() { client.RemoveLocationUpdatesAsync(locationCallback); }
async Task RemoveRequestingLocationUpdates() { await fusedLocationProviderClient.RemoveLocationUpdatesAsync(locationCallback); }
public async Task StopLocationUpdates() { await _locationProvider.RemoveLocationUpdatesAsync(_locationCallback); _locationUpdatesStarted = false; }
public async void Stop() => await client.RemoveLocationUpdatesAsync(locationCallback);
public async Task StopLocationUpdates() { await locationProvider.RemoveLocationUpdatesAsync(locationCallback); }
public void Stop() { _LocationChanged = null; _LocationError = null; Task.Run(async() => await _Client.RemoveLocationUpdatesAsync(this)); }