Ejemplo n.º 1
0
        private void HandlePositionUpdateDebugData(PostionUpdateDebugData postionUpdateDebugData)
        {
            var debugMessage = postionUpdateDebugData.GetDebugNotifyMessage();

            Debug.WriteLine(debugMessage);

            if (!BackgroundGeoLocationOptions.Debug)
            {
                return;
            }

            switch (postionUpdateDebugData.PositionUpdateType)
            {
            case PositionUpdateType.SkippedBecauseOfDistance:
                _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.Low));
                break;

            case PositionUpdateType.NewPosition:
                _debugNotifier.Notify(debugMessage, new Tone(750, Frequency.High));
                break;

            case PositionUpdateType.EnteringStationary:
                _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.High), new Tone(250, Frequency.High));
                break;

            case PositionUpdateType.StationaryUpdate:
                _debugNotifier.Notify(debugMessage, new Tone(750, Frequency.Low), new Tone(750, Frequency.Low));
                break;

            case PositionUpdateType.ExitStationary:
                _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.High), new Tone(250, Frequency.High), new Tone(250, Frequency.High));
                break;
            }
        }
        private StationaryUpdateResult StationaryUpdate(Geoposition geoPosition, Position newPosition)
        {
            if (!_stationaryManager.InStationary)
            {
                return(StationaryUpdateResult.NotInStationary);
            }

            var newStationaryReportInterval = _stationaryManager.GetNewReportInterval(newPosition);

            if (!newStationaryReportInterval.HasValue || !_stationaryManager.InStationary)
            {
                return(StationaryUpdateResult.ExitedFromStationary);
            }

            PositionChanged(this, new GeolocatorWrapperPositionChangedEventArgs
            {
                GeolocatorLocationStatus = Geolocator.LocationStatus,
                Position = geoPosition,
                PositionUpdateDebugData =
                    PostionUpdateDebugData.ForStationaryUpdate((uint)newStationaryReportInterval,
                                                               _stationaryManager.GetDistanceToStationary(newPosition))
            });

            // stay in stationary
            UpdateReportInterval((uint)newStationaryReportInterval);

            return(StationaryUpdateResult.InStationary);
        }
        private void SkipPosition(bool becauseOfEnteringStationary, bool startStationary, double?distance)
        {
            var updateType = becauseOfEnteringStationary ? PositionUpdateType.EnteringStationary : PositionUpdateType.SkippedBecauseOfDistance;

            PositionChanged(this, new GeolocatorWrapperPositionChangedEventArgs
            {
                EnteredStationary       = startStationary,
                PositionUpdateDebugData = PostionUpdateDebugData.ForSkip(updateType, distance, _distanceFilter, _stationaryRadius)
            });
        }
        private void OnGeolocatorPositionChanged(Geolocator sender, PositionChangedEventArgs positionChangesEventArgs)
        {
            if (_skipNextPosition)
            {
                _skipNextPosition = false;
                return;
            }

            var newGeoCoordinate = new GeoCoordinate(positionChangesEventArgs.Position.Coordinate.Latitude, positionChangesEventArgs.Position.Coordinate.Longitude);
            var newPosition      = new Position(newGeoCoordinate, DateTime.Now, positionChangesEventArgs.Position.Coordinate.Accuracy);

            _positionPath.AddPosition(newPosition);

            var stationaryUpdateResult = StationaryUpdate(positionChangesEventArgs.Position, newPosition);

            if (stationaryUpdateResult == StationaryUpdateResult.InStationary)
            {
                return;
            }

            var currentAvgSpeed = _positionPath.GetCurrentSpeed(TimeSpan.FromMilliseconds(_reportInterval * 5)); // avg speed of last 5 (at max) positions

            var updateScaledDistanceFilterResult = UpdateScaledDistanceFilter(currentAvgSpeed, positionChangesEventArgs.Position.Coordinate);

            if (updateScaledDistanceFilterResult.SkipPositionBecauseOfDistance)
            {
                SkipPosition(updateScaledDistanceFilterResult.StartStationary, updateScaledDistanceFilterResult.StartStationary, updateScaledDistanceFilterResult.Distance);
                return;
            }

            var newReportInterval = CalculateNewReportInterval(currentAvgSpeed);

            if (updateScaledDistanceFilterResult.ScaledDistanceFilterChanged)
            {
                UpdateReportInterval(newReportInterval);
            }

            PositionChanged(this, new GeolocatorWrapperPositionChangedEventArgs
            {
                GeolocatorLocationStatus = Geolocator.LocationStatus,
                Position                = positionChangesEventArgs.Position,
                EnteredStationary       = false,
                PositionUpdateDebugData = PostionUpdateDebugData.ForNewPosition(positionChangesEventArgs, currentAvgSpeed, updateScaledDistanceFilterResult, Geolocator.ReportInterval, stationaryUpdateResult == StationaryUpdateResult.ExitedFromStationary)
            });
        }
        private void HandlePositionUpdateDebugData(PostionUpdateDebugData postionUpdateDebugData)
        {
            var debugMessage = postionUpdateDebugData.GetDebugNotifyMessage();
            Debug.WriteLine(debugMessage);

            if (!BackgroundGeoLocationOptions.Debug) return;

            switch (postionUpdateDebugData.PositionUpdateType)
            {
                case PositionUpdateType.SkippedBecauseOfDistance:
                    _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.Low));
                    break;
                case PositionUpdateType.NewPosition:
                    _debugNotifier.Notify(debugMessage, new Tone(750, Frequency.High));
                    break;
                case PositionUpdateType.EnteringStationary:
                    _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.High), new Tone(250, Frequency.High));
                    break;
                case PositionUpdateType.StationaryUpdate:
                    _debugNotifier.Notify(debugMessage, new Tone(750, Frequency.Low), new Tone(750, Frequency.Low));
                    break;
                case PositionUpdateType.ExitStationary:
                    _debugNotifier.Notify(debugMessage, new Tone(250, Frequency.High), new Tone(250, Frequency.High), new Tone(250, Frequency.High));
                    break;
            }
        }