private void Error(MvxLocationError error) { var message = new LocationMessage(this, -1, -1, true, error.Code.ToString()); _watcher.Stop(); _messenger.Publish(message); }
public void Stop() { if (_locationWatcher != null) { _locationWatcher.Stop(); } }
public void Init() { if (!locationWatcher.Started) { locationWatcher.Start( new MvxLocationOptions { Accuracy = MvxLocationAccuracy.Coarse }, loc => { UserLocation = loc; const double tolerance = 0.001; if (Math.Abs(loc.Coordinates.Latitude) > tolerance && Math.Abs(loc.Coordinates.Longitude) > tolerance) { locationWatcher.Stop(); } }, error => { }); } // defaults userAge = 0; userId = string.Empty; userGender = Gender.Unknown; userLocation = new MvxGeoLocation { Coordinates = new MvxCoordinates { Latitude = 0, Longitude = 0, Accuracy = 0 } }; }
public Task <MvxGeoLocation> GetLocation(CancellationTokenSource tokenSource = null) { var tcs = new TaskCompletionSource <MvxGeoLocation>(); StopLocationWatcher(); _locationWatcher.Start(new MvxLocationOptions() { Accuracy = MvxLocationAccuracy.Coarse, TrackingMode = MvxLocationTrackingMode.Background }, location => { tcs.TrySetResult(location); _locationWatcher.Stop(); }, error => { tcs.TrySetResult(null); }); Task.Run(async() => { if (tokenSource != null) { await Task.Delay(60000, tokenSource.Token); } else { await Task.Delay(60000); } if (!tcs.Task.IsCompleted) { MvxGeoLocation currLocation = null; try { currLocation = _locationWatcher.CurrentLocation; } catch { } tcs.TrySetResult(currLocation); } }); return(tcs.Task); }
private void OnLocationFound(MvxGeoLocation location) { _locationWatcher.Stop(); _currentLocation = location; MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map_screen); mapFrag.GetMapAsync(this); }
public void onError(MvxLocationError error) { if (options.Accuracy == MvxLocationAccuracy.Fine && (DateTime.Now - _locationAcquired).TotalSeconds > 30) { if (_location.Started) { return; } _location.Stop(); options.Accuracy = MvxLocationAccuracy.Coarse; InitializeLocation(options); } if ((DateTime.Now - _locationAcquired).TotalSeconds > 30) { LocationAvailable = false; } }
public void Stop() { if (!isStarted) { return; } isStarted = false; watcher.Stop(); }
public FirstViewModel(IMvxLocationWatcher locationWatcher) { _locationWatcher = locationWatcher; _locationWatcher.Start(new MvxLocationOptions { Accuracy = MvxLocationAccuracy.Fine }, OnLocation, OnError); _lat = _locationWatcher.CurrentLocation.Coordinates.Latitude; _lng = _locationWatcher.CurrentLocation.Coordinates.Longitude; _locationWatcher.Stop(); System.Diagnostics.Debug.WriteLine($"Lat: {Lat} Lng: {Lng}"); }
private void StartWatcher() { Console.WriteLine("StartWatcher"); _dispatcher.ExecuteOnMainThreadAsync(() => { if (_locationWatcher.Started) { Console.WriteLine("Watcher already started!"); return; } _locationWatcher.Start(new MvxLocationOptions() { Accuracy = MvxLocationAccuracy.Coarse }, location => { _locationWatcher.Stop(); OnSuccess(new MvxCoordinates() { Latitude = location.Coordinates.Latitude, Longitude = location.Coordinates.Longitude }); }, error => { _locationWatcher.Stop(); Console.WriteLine(error.Code); OnError(new Exception(error.Code.ToString())); }); Task.Delay(_timeOut).ContinueWith(_ => OnTimeout()); }); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (_locationWatcher.Started) { _locationWatcher.Stop(); } } _disposed = true; } }
public void StopLocationWatcher() { _watcher.Stop(); }
public void Stop() { _watcher.Stop(); }
public void Stop() => _watcher.Stop();