From 6d69dfddcff783bca20e688211868d7acf47b7c9 Mon Sep 17 00:00:00 2001 From: Shan Ma Date: Tue, 29 Jun 2021 16:45:36 -0700 Subject: [PATCH] add documentation and remove unecessary didSet trigger --- .../Examples/Custom-User-Location.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Navigation-Examples/Examples/Custom-User-Location.swift b/Navigation-Examples/Examples/Custom-User-Location.swift index 4d8bdd88..1367906d 100644 --- a/Navigation-Examples/Examples/Custom-User-Location.swift +++ b/Navigation-Examples/Examples/Custom-User-Location.swift @@ -8,6 +8,7 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg var navigationMapView: NavigationMapView! { didSet { + // After the start of active turn-by-turn navigation, the previous `navigationMapView` should be `nil` and removed from super view. It could avoid the location update in the background to disturb the turn-by-turn navigation guidance. if let navigationMapView = oldValue { navigationMapView.removeFromSuperview() } @@ -46,13 +47,7 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg } } - var waypoints: [Waypoint] = [] { - didSet { - waypoints.forEach { - $0.coordinateAccuracy = -1 - } - } - } + var waypoints: [Waypoint] = [] var startButtonHighlighted:Bool = false { didSet { @@ -139,6 +134,8 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg let waypoint = Waypoint(coordinate: destinationCoordinate, name: "Dropped Pin #\(waypoints.endIndex + 1)") waypoint.targetCoordinate = destinationCoordinate + // Change the coordinate accuracy of `Waypoint` to negative beofre add it to the `waypoints`. Thus the route requested on the `waypoints` is considered viable. + waypoint.coordinateAccuracy = -1 waypoints.append(waypoint) requestRoute() @@ -152,6 +149,8 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg } let userWaypoint = Waypoint(location: currentLocation) + // Change the coordinate accuracy of `Waypoint` to negative beofre add it to the `waypoints`. Thus the route requested on the `waypoints` is considered viable. + userWaypoint.coordinateAccuracy = -1 waypoints.insert(userWaypoint, at: 0) let navigationRouteOptions = NavigationRouteOptions(waypoints: waypoints) @@ -293,7 +292,7 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg navigationViewController.navigationMapView?.mapView.mapboxMap.style.uri = navigationMapView.mapView?.mapboxMap.style.uri present(navigationViewController, animated: true) { - self.navigationMapView.removeFromSuperview() + // When start navigation, the previous `navigationMapView` should be `nil` and removed from super view. The niled out `navigationMapView` could avoid the location provider sending location update in the background, which will disturb the turn-by-turn navigation guidance. self.navigationMapView = nil } }