Skip to content

Commit

Permalink
add documentation and remove unecessary didSet trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanMa1991 committed Jun 29, 2021
1 parent bd7ae3d commit 6d69dfd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Navigation-Examples/Examples/Custom-User-Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6d69dfd

Please sign in to comment.