private RoutePoint GetNextPointOnRoute(GeoPosition position, Distance maxSkipDistance) { var last = GetLastWayPoint(); var skipDistance = 0d; foreach (var routePoint in _route.GetEnumerable(NextWaypoint, NavigationDirection)) { var expectedPosition = MapExtensions.ClosestPositionBetweenPoints(last, routePoint, position); skipDistance += last.Distance(routePoint); if (VisitedWaypoints.Contains(routePoint) || skipDistance > maxSkipDistance.Miles) { break; } if (IsOnRoute(expectedPosition, position)) { return(last); } last = routePoint; } return(null); }
public async Task SkipToCurrentLocation() { var position = (await _geoLocator.GetPositionAsync()).ToGeoPosition(); var expectedPosition = MapExtensions.ClosestPositionBetweenPoints(GetLastWayPoint(), NextWaypoint, position); if (!IsOnRoute(expectedPosition, position)) { var possibleSkip = GetNextPointOnRoute(position, Distance.FromKilometers(5)); if (possibleSkip != null) { do { ActivateNextWaypoint(); } while (GetLastWayPoint() != possibleSkip); } } }
public void OnLocationUpdate(object sender, PositionEventArgs e) { var position = e.Position.ToGeoPosition(); var expectedPosition = MapExtensions.ClosestPositionBetweenPoints(GetLastWayPoint(), NextWaypoint, position); var isOnRoute = IsOnRoute(expectedPosition, position); if (!isOnRoute) { var possibleSkip = GetNextPointOnRoute(position, _maxSkippingDistance); if (possibleSkip != null) { do { ActivateNextWaypoint(); } while (GetLastWayPoint() != possibleSkip); } else if (_showOffRouteMessage) { if (!(Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault() is OffRoutePage)) { Application.Current.MainPage.Navigation.PushAsync(new OffRoutePage(this)); } } } if (HasArrivedAtWaypoint(position)) { ActivateNextWaypoint(); if (GetLastWayPoint() is PointOfInterest poi) { ShowPointOfInterestModal(poi); } } UpdateMap(position, expectedPosition, isOnRoute); UpdateStats(GetLastWayPoint().Distance(expectedPosition)); }