Skip to content

Commit 0710198

Browse files
committed
Use the same algorithm for calculating distance to intersection as in distance traveled
1 parent 25678d8 commit 0710198

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* Fixed an issue where the route progress could be incorrectly calculated for folding back route steps. ([#4234](https://github.com/mapbox/mapbox-navigation-ios/pull/4234))
5757
* `NavigationView.init(frame:tileStoreLocation:navigationMapView:)`, `NavigationView.navigationMapView`, `NavigationView.floatingStackView`, `NavigationView.floatingButtons`, `NavigationView.wayNameView`, `NavigationView.speedLimitView`, `NavigationView.topBannerContainerView` and `NavigationView.bottomBannerContainerView` are now publicly accessible. ([#4249](https://github.com/mapbox/mapbox-navigation-ios/pull/4249))
5858
* Fixed an issue where empty intersections of the current step could cause a crash. ([#4260](https://github.com/mapbox/mapbox-navigation-ios/pull/4260))
59+
* Fixed an issue where `RouteProgress.currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection` could be incorrectly calculated for folding back route steps. ([#]())
5960
* Deprecated `NavigationSettings.initialize(directions:tileStoreConfiguration:routingProviderSource:alternativeRouteDetectionStrategy:utilizeSensorData:navigatorPredictionInterval:liveIncidentsOptions:statusUpdatingSettings:)` method in favor of `NavigationSettings.initialize(with:)`. ([#4275](https://github.com/mapbox/mapbox-navigation-ios/pull/4275))
6061
* Added new parameter that allows configuring logging level for Mapbox SDKs. Checkout new `NavigationSettings.initialize(with:)` method for more information. ([#4275](https://github.com/mapbox/mapbox-navigation-ios/pull/4275))
6162
* Fixed an issue where the `UserHaloCourseView` will be shown under reduced location accuracy mode with `NavigationMapview.reducedAccuracyActivatedMode` as `false`. Right now `UserHaloCourseView` will be applied in only one case: when user explicitly sets `NavigationMapView.reducedAccuracyActivatedMode` to `true`, and the `Precise Location` property in the settings of current application is disabled by user. ([#4285](https://github.com/mapbox/mapbox-navigation-ios/pull/4285))

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ open class RouteController: NSObject {
388388
updateSpokenInstructionProgress(status: status, willReRoute: isRerouting)
389389
updateVisualInstructionProgress(status: status)
390390
updateRoadName(status: status)
391-
routeProgress.updateDistanceToIntersection(from: snappedLocation)
392-
391+
393392
rerouteAfterArrivalIfNeeded(snappedLocation, status: status)
394393

395394
if status.routeState != .complete {
@@ -507,6 +506,7 @@ open class RouteController: NSObject {
507506

508507
private func update(progress: RouteProgress, status: NavigationStatus, with location: CLLocation, rawLocation: CLLocation, upcomingRouteAlerts routeAlerts: [UpcomingRouteAlert], mapMatchingResult: MapMatchingResult, routeShapeIndex: Int) {
509508
progress.updateDistanceTraveled(navigationStatus: status)
509+
510510
progress.upcomingRouteAlerts = routeAlerts.map { RouteAlert($0) }
511511
progress.shapeIndex = routeShapeIndex
512512

Sources/MapboxCoreNavigation/RouteProgress.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ open class RouteProgress: Codable {
164164
intersectionIndex: currentLegProgress.currentStepProgress.intersectionIndex)
165165
calculateLegsCongestion()
166166
updateDistanceTraveled(with: location)
167-
updateDistanceToIntersection(from: location)
168167
}
169168

170169
/**
@@ -200,24 +199,31 @@ open class RouteProgress: Codable {
200199
else {
201200
updateDistanceTraveled(with: .init(navigationStatus.location))
202201
}
202+
updateDistanceToIntersection()
203203
}
204204

205205
/**
206206
Update the distance to intersection according to new location specified.
207207
- parameter location: Updated user location.
208208
*/
209-
func updateDistanceToIntersection(from location: CLLocation) {
209+
private func updateDistanceToIntersection() {
210210
guard var intersections = currentLegProgress.currentStepProgress.step.intersections else { return }
211211

212212
// The intersections array does not include the upcoming maneuver intersection.
213213
if let upcomingIntersection = currentLegProgress.upcomingStep?.intersections?.first {
214214
intersections += [upcomingIntersection]
215215
}
216216
currentLegProgress.currentStepProgress.intersectionsIncludingUpcomingManeuverIntersection = intersections
217-
217+
218218
if let shape = currentLegProgress.currentStep.shape,
219-
let upcomingIntersection = currentLegProgress.currentStepProgress.upcomingIntersection {
220-
currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection = shape.distance(from: location.coordinate, to: upcomingIntersection.location)
219+
let upcomingIntersection = currentLegProgress.currentStepProgress.upcomingIntersection,
220+
let coordinateOnStep = shape.coordinateFromStart(
221+
distance: currentLegProgress.currentStepProgress.distanceTraveled
222+
) {
223+
currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection = shape.distance(
224+
from: coordinateOnStep,
225+
to: upcomingIntersection.location
226+
)
221227
}
222228

223229
updateIntersectionDistances()

0 commit comments

Comments
 (0)