protected virtual void OnNewPosition(PositionEventArgs e) { if (NewPosition != null) { NewPosition(this, e); } }
/// <summary> /// Update the Pace information /// </summary> /// <returns></returns> public async Task UpdatePosition() { //if (Paused) return; if (_isPositionUpdating) { return; } try { //Only update every 5 seconds if (_lastPositionUpdate != null) { TimeSpan _difference = DateTime.Now - _lastPositionUpdate; if (_difference.TotalSeconds < 5) { return; } } _isPositionUpdating = true; //Get current position _lastPositionUpdate = DateTime.Now; Geoposition _pos = await Geolocator.GetGeopositionAsync(); _lastPosition = _pos; if (!Paused) { Measurement _newMeasurement = AddMeasurement(); //Fire event PositionEventArgs _arg = new PositionEventArgs(); _arg.Position = _newMeasurement.Position; OnNewPosition(_arg); } //Send message to Pebble Time //SendPebblePaceMessage(); } catch (Exception) { } _isPositionUpdating = false; }