Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always send progress update except when location is unqualified #1126

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions MapboxCoreNavigation/MBRouteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
Posted when `MBRouteController` receives a user location update representing movement along the expected route.

The user info dictionary contains the keys `MBRouteControllerRouteProgressKey`, `MBRouteControllerLocationKey`, and `MBRouteControllerEstimatedTimeUntilManeuverKey`.
The user info dictionary contains the keys `MBRouteControllerRouteProgressKey` and `MBRouteControllerLocationKey`.

:nodoc:
*/
Expand Down Expand Up @@ -62,11 +62,6 @@ extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerRouteProg
*/
extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerLocationKey;

/**
A key in the user info dictionary of a `Notification.Name.RouteControllerProgressDidChange` notification. The corresponding value is an `NSNumber` instance containing a double value indicating the estimated time remaining, in seconds, until the user reaches the next maneuver point.
*/
extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerEstimatedTimeUntilManeuverKey;

/**
A key in the user info dictionary of a `Notification.Name.RouteControllerDidFailToReroute` notification. The corresponding value is an `NSError` object indicating why `RouteController` was unable to calculate a new route.
*/
Expand Down
1 change: 0 additions & 1 deletion MapboxCoreNavigation/MBRouteController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

const MBRouteControllerNotificationUserInfoKey MBRouteControllerRouteProgressKey = @"progress";
const MBRouteControllerNotificationUserInfoKey MBRouteControllerLocationKey = @"location";
const MBRouteControllerNotificationUserInfoKey MBRouteControllerEstimatedTimeUntilManeuverKey = @"seconds";
const MBRouteControllerNotificationUserInfoKey MBRouteControllerRoutingErrorKey = @"error";
const MBRouteControllerNotificationUserInfoKey MBRouteControllerIsOpportunisticKey = @"RouteControllerDidFindFasterRoute";

Expand Down
18 changes: 6 additions & 12 deletions MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Notification.Name {
/**
Posted when `RouteController` receives a user location update representing movement along the expected route.

The user info dictionary contains the keys `RouteControllerNotificationUserInfoKey.routeProgressKey`, `RouteControllerNotificationUserInfoKey.locationKey`, and `RouteControllerNotificationUserInfoKey.estimatedTimeUntilManeuverKey`.
The user info dictionary contains the keys `RouteControllerNotificationUserInfoKey.routeProgressKey` and `RouteControllerNotificationUserInfoKey.locationKey`.
*/
public static let routeControllerProgressDidChange = MBRouteControllerProgressDidChange

Expand Down Expand Up @@ -617,30 +617,24 @@ extension RouteController: CLLocationManagerDelegate {
}

let polyline = Polyline(routeProgress.currentLegProgress.currentStep.coordinates!)
guard let userSnapToStepDistanceFromManeuver = userSnapToStepDistanceFromManeuver else { return }
let secondsToEndOfStep = userSnapToStepDistanceFromManeuver / location.speed
let currentStepProgress = routeProgress.currentLegProgress.currentStepProgress
let currentStep = currentStepProgress.step

// Notify observers if the step’s remaining distance has changed.
if let closestCoordinate = polyline.closestCoordinate(to: location.coordinate) {
let remainingDistance = polyline.distance(from: closestCoordinate.coordinate)
let distanceTraveled = currentStep.distance - remainingDistance
if distanceTraveled != currentStepProgress.distanceTraveled {
currentStepProgress.distanceTraveled = distanceTraveled
NotificationCenter.default.post(name: .routeControllerProgressDidChange, object: self, userInfo: [
RouteControllerNotificationUserInfoKey.routeProgressKey: routeProgress,
RouteControllerNotificationUserInfoKey.locationKey: location,
RouteControllerNotificationUserInfoKey.estimatedTimeUntilManeuverKey: secondsToEndOfStep
])
}
currentStepProgress.distanceTraveled = distanceTraveled
NotificationCenter.default.post(name: .routeControllerProgressDidChange, object: self, userInfo: [
RouteControllerNotificationUserInfoKey.routeProgressKey: routeProgress,
RouteControllerNotificationUserInfoKey.locationKey: location
])
}

updateDistanceToIntersection(from: location)
updateRouteStepProgress(for: location)
updateRouteLegProgress(for: location)


guard userIsOnRoute(location) || !(delegate?.routeController?(self, shouldRerouteFrom: location) ?? true) else {
reroute(from: location)
return
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public class NavigationViewController: UIViewController, RouteMapViewControllerD
@objc func progressDidChange(notification: NSNotification) {
let routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as! RouteProgress
let location = notification.userInfo![RouteControllerNotificationUserInfoKey.locationKey] as! CLLocation
let secondsRemaining = notification.userInfo![RouteControllerNotificationUserInfoKey.estimatedTimeUntilManeuverKey] as! TimeInterval
let secondsRemaining = routeProgress.currentLegProgress.currentStepProgress.durationRemaining

mapViewController?.notifyDidChange(routeProgress: routeProgress, location: location, secondsRemaining: secondsRemaining)

Expand Down