• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Custom Waypoint arrival screen

Customize the arrival experience to enhance user engagement and control during their navigation journey.

This example shows:

  • How to customize the arrival screen when arriving at a waypoint of the route

  • In the example code, arrival screen will show the waypoint name and user could choose to continue navigating to next waypoint

For all code examples, refer to Navigation Code Examples

CustomWaypointScreenController view source

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
54
55
56
57
58
import UIKit
import NbmapNavigation
import NbmapCoreNavigation
import NbmapDirections

class CustomWaypointScreenController: UIViewController {
  
   override func viewDidLoad() {
       super.viewDidLoad()
      
       let origin = CLLocation(latitude: 37.77440680146262, longitude: -122.43539772352648)
       let waypoint = CLLocation(latitude: 37.76856957793795, longitude: -122.42709811526268)
       let destination = CLLocation(latitude: 37.76556957793795, longitude: -122.42409811526268)
       let options = NavigationRouteOptions(locations: [origin,waypoint,destination])
       Directions.shared.calculate(options) { [weak self] routes, error in
           guard let strongSelf = self else {
               return
           }
           guard error == nil else {
               print(error!)
               return
           }
          
           guard let routes = routes else { return }
          
           let navigationService = NBNavigationService(routes: routes, routeIndex: 0, simulating : simulationIsEnabled ? SimulationMode.always : SimulationMode.onPoorGPS)
          
           let navigationOptions = NavigationOptions(navigationService: navigationService)
          
           let navigationViewController = NavigationViewController(for: routes,navigationOptions: navigationOptions)
           navigationViewController.modalPresentationStyle = .fullScreen
           navigationViewController.delegate = self
          
           // Start navigation
           strongSelf.present(navigationViewController, animated: true, completion: nil)
       }
   }
}

extension CustomWaypointScreenController : NavigationViewControllerDelegate {
   func navigationViewController(_ navigationViewController: NavigationViewController, didArriveAt waypoint: Waypoint) -> Bool {
       let isFinalLeg = navigationViewController.navigationService.routeProgress.isFinalLeg
       if isFinalLeg {
           return true
       }
      
       let alert = UIAlertController(title: "Arrived at \(waypoint.name ?? "Unknown").", message: "Would you like to continue?", preferredStyle: .alert)
       alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { _ in
           // Begin the next leg once the driver confirms
           guard !isFinalLeg else { return }
           navigationViewController.navigationService.router.routeProgress.legIndex += 1
           navigationViewController.navigationService.start()
       }))
       navigationViewController.present(alert, animated: true, completion: nil)
      
       return false
   }
}

This class is a view controller that allows users to navigate to a destination with waypoints. The class has the following properties:

  • origin: The origin location of the navigation.

  • waypoint: The waypoint location of the navigation.

  • destination: The destination location of the navigation.

  • routes: An array of Route objects that represent the routes between the origin, waypoint, and destination.

  • navigationService: A NBNavigationService object that is used to control the navigation.

  • navigationViewController: A NavigationViewController object that is used to display the navigation.

The class has the following methods:

  • viewDidLoad(): This method is called when the view controller is loaded. In this method, the navigation service is created and configured.

  • didArriveAtWaypoint(): This method is called when the navigation service arrives at a waypoint. In this method, an alert is presented to the user asking if they would like to continue to the next waypoint.

The code you provided also has an extension:

  • CustomWaypointScreenController: NavigationViewControllerDelegate

This extension conforms the CustomWaypointScreenController class to the NavigationViewControllerDelegate protocol. This protocol allows the CustomWaypointScreenController class to respond to events from the navigation controller.

ios-sdk-7