forked from stadiamaps/ferrostar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationDelegate.swift
More file actions
53 lines (50 loc) · 2.39 KB
/
Copy pathNavigationDelegate.swift
File metadata and controls
53 lines (50 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import CoreLocation
import FerrostarCore
import FerrostarCoreFFI
/// Not all navigation apps will require a navigation delegate. In fact, we hope that most don't!
/// In case you do though, this sample implementation shows what you'll need to get started
/// by re-implementing the default behaviors of the core.
class NavigationDelegate: FerrostarCoreDelegate {
func core(_: FerrostarCore, didStartWith _: Route) {
// TODO: Create defaults extension on FerrostarCoreDelegate
}
func core(_: FerrostarCore, correctiveActionForDeviation _: DeviationKind,
remainingWaypoints waypoints: [Waypoint]) -> CorrectiveAction
{
// If the user is off course, we'll try to calculate a new route using the remaining waypoints.
.getNewRoutes(waypoints: waypoints)
}
func core(_ core: FerrostarCore, loadedAlternateRoutes routes: [Route]) {
// Automatically accept the first new route if the framework was calculating a new route
// due to the user being off course.
// Pretty sensible default.
if core.state?.isCalculatingNewRoute ?? false,
let route = routes.first
{
do {
// Most implementations will probably reuse existing configs (the default implementation does),
// but we provide devs with flexibility here.
let config = SwiftNavigationControllerConfig(
waypointAdvance: .waypointWithinRange(100.0),
stepAdvanceCondition: stepAdvanceDistanceEntryAndExit(
distanceToEndOfStep: 30,
distanceAfterEndOfStep: 2,
minimumHorizontalAccuracy: 32
),
arrivalStepAdvanceCondition: stepAdvanceDistanceToEndOfStep(
distance: 30,
minimumHorizontalAccuracy: 32
),
routeDeviationTracking: .staticThreshold(minimumHorizontalAccuracy: 25, maxAcceptableDeviation: 20),
snappedLocationCourseFiltering: .snapToRoute
)
try core.startNavigation(
route: route,
config: config
)
} catch {
// Users of the framework my develop their own responses here, such as notifying the user if appropriate
}
}
}
}