/// <summary> /// Notifies the location update. /// </summary> /// <param name="locationArgs">Location arguments.</param> protected void NotifyLocationUpdate(LocationUpdatedEventArgs locationArgs) { var location = locationArgs.Location; var newLocation = new Location() { Longitude = location.Longitude, Latitude = location.Latitude, Timestamp = DateTime.Now, }; CurrentLocation = newLocation; Locations.Add(newLocation); LocationUpdate?.Invoke(this, newLocation); // stop any more location updates LocationManager.Stop(); LocationLoading = false; }
private bool BeginListening() { if (LocationUpdate != null) { try { var request = new GeolocationRequest(GeolocationAccuracy.High, new TimeSpan(0, 0, 2)); // This can't be called from a background thread, bug https://github.com/xamarin/Essentials/issues/634 var task = Geolocation.GetLocationAsync(request); task.ContinueWith(x => { try { if (x.IsCompleted) { var location = x.Result; if (location == null) { _location.Update("Timed out getting location"); Alert?.Invoke(this, new AlertEventArgs(true)); } else { _location.Update(location.Latitude, location.Longitude, location.Accuracy, location.Altitude, location.Speed, location.Course, location.Timestamp); Alert?.Invoke(this, new AlertEventArgs(false)); } } } catch { _location.Update("Unknown error"); Alert?.Invoke(this, new AlertEventArgs(true)); } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch (FeatureNotSupportedException e) { // Handle not supported on device exception _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } catch (PermissionException e) { // Handle permission exception _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } catch (Exception e) { // Unable to get location _location.Update(string.Format("{0}", e.Message)); Alert?.Invoke(this, new AlertEventArgs(true)); } LocationUpdate?.Invoke(this, new LocationEventArgs(_location)); } return(true); }
private void reader_LocationUpdated(object sender, ClientModels.EDLog e) { LocationUpdate?.Invoke(this, e.Location); }