private void HandleTimeout(object state) { if (state != null && (bool)state) { this.tcs.TrySetCanceled(); } if (this.bestPosition != null) { this.tcs.TrySetResult(GeolocatorImplementation.GetPosition(this.bestPosition)); } else { this.tcs.TrySetCanceled(); } }
private void WatcherOnPositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e) { if (e.Position.Location.IsUnknown) { return; } bool isRecent = timeout == Timeout.Infinite || (e.Position.Timestamp - this.start).TotalMilliseconds < this.timeout; if (e.Position.Location.HorizontalAccuracy <= this.desiredAccuracy && isRecent) { this.tcs.TrySetResult(GeolocatorImplementation.GetPosition(e.Position)); } if (this.bestPosition == null || e.Position.Location.HorizontalAccuracy < this.bestPosition.Location.HorizontalAccuracy) { this.bestPosition = e.Position; } }