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

Open RouteController to custom location snapping #85

Merged
merged 3 commits into from
Jul 18, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
self.startNavigation(with: route, animated: false)
#endif
```
* Custom location snapping in the `RouteController` via the delegate

## 3.0.0 (Jun 15, 2024)
* The `speak` method in `RouteVoiceController` can be used without a given `RouteProgress` or the `RouteProgress` can explicitly ignored so that it will not be added to the voice instruction.
Expand Down
7 changes: 6 additions & 1 deletion MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@
- important: If the rawLocation is outside of the route snapping tolerances, this value is nil.
*/
var snappedLocation: CLLocation? {
self.rawLocation?.snapped(to: self.routeProgress.currentLegProgress)
guard let raw = self.rawLocation else {
return nil
}

let customSnap = self.delegate?.routeControllerSnap?(rawLocation: raw)
return customSnap ?? raw.snapped(to: self.routeProgress.currentLegProgress)
}

var heading: CLHeading?
Expand Down Expand Up @@ -664,7 +669,7 @@
if let _ = error { return }
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { return }

guard let data, let currentVersion = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .newlines) else { return }

Check warning on line 672 in MapboxCoreNavigation/RouteController.swift

View workflow job for this annotation

GitHub Actions / Code Style

Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)

if latestVersion != currentVersion {
let updateString = NSLocalizedString("UPDATE_AVAILABLE", bundle: .mapboxCoreNavigation, value: "Mapbox Navigation SDK for iOS version %@ is now available.", comment: "Inform developer an update is available")
Expand Down
9 changes: 9 additions & 0 deletions MapboxCoreNavigation/RouteControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,13 @@ public protocol RouteControllerDelegate: AnyObject {
*/
@objc(routeControllerGetDirections:along:completion:)
optional func routeControllerGetDirections(from location: CLLocation, along progress: RouteProgress, completion: @escaping (_ mostSimilarRoute: Route?, _ routes: [Route]?, _ error: Error?) -> Void) -> Bool

/**
Allows to customize the snapping of raw and pre-snapped location. If no implementation is provided, the default snapping will be used.

- parameter rawLocation: The raw location from the controller
- returns: The snapped location or nil if snapping were impossible.
*/
@objc(routeControllerSnapLocation:)
optional func routeControllerSnap(rawLocation: CLLocation) -> CLLocation?
}
Loading