The core component of Navmii SDK responsible for route navigation is NMRouteNavigator. This class provides the API to control the route navigation process, to get navigation information and guidance updates. The class is also able to handle the rerouting and the rerouting by traffic.

CREATING ROUTE NAVIGATOR

NMSdk class contains the routeNavigator property providing access to the instance of NMRouteNavigator. The route navigator instance can be accessed only after the SDK was started.

USING ROUTE NAVIGATOR

Route navigator has different responsibilities all related to each other:

ROUTE NAVIGATION

Route navigation starts by calling the startNavigatingTheRoute: method. The route parameter is an instance of NMRoute class which represents a route to navigate. The source of routes is Routing Service. After the route navigation has started, the route navigator gets GPS position updates internally, updates the route navigation state and notifies if any changes occur. Those "notifications" can be gotten by conforming to NMRouteNavigationListener protocol. Callbacks for the following events are available:

Route navigator has properties to access the latest route navigation information at any time.

Route navigator also provides the route navigation guidance whose callbacks can be gotten by conforming to NMGuidanceListener protocol.

User is able to stop the route navigation by calling the stopNavigation method.

AUTOMATIC REROUTING HANDLING

As mentioned above NMRouteNavigator is able to handle rerouting automatically. The feature is enabled by default, but NMRouteNavigator class has the reroutingEnabled property, which can be used to disable or enable the feature. If automatic rerouting handling is enabled, the route navigator tracks the on-route state and, once the GPS position has got off the route, calculates a new route and applies it. Callbacks about the automatic rerouting process can be gotten by conforming to NMReroutingListener protocol. The protocol has the onReroutingStarted method, which is called once automatic rerouting starts, and the onReroutingFinished: method, which is called once the process finishes. The onReroutingFinished: method has the newRoute parameter, which is a new instance of NMRoute class representing the new route being navigated. The newRoute can be nil if rerouting handling is no longer required (i.e. GPS position has returned back to the previous route).

The rerouting engine has an algorithm, which tries to use a route the most similar to the one passed to the startNavigatingTheRoute: method. NMRouteNavigator has the reroutingSettings property, which allows to tune the algorithm.

AUTOMATIC REROUTING BY TRAFFIC HANDLING

As mentioned above NMRouteNavigator is able to handle rerouting by traffic automatically. The feature is enabled by default, but NMRouteNavigator class has the reroutingByTrafficEnabled property, which can be used to disable or enable the feature. If automatic rerouting by traffic is enabled, the route navigator internally gets notifications from the traffic service that traffic near the current position has been updated, and, once it happens, handles rerouting by traffic. The SDK user gets callbacks about the rerouting by traffic process by conforming to NMReroutingByTrafficListener protocol. The protocol has a single method, which is called once the rerouting by traffic occurred. Here is the method declaration:

- (void)onReroutingByTrafficOccurredWithOldTimeToDestination:(NSInteger)oldTimeToDestinationInSeconds
                                        newTimeToDestination:(NSInteger)newTimeToDestinationInSeconds
                                                    newRoute:(nullable NMRoute *)newRoute
                                          resemblingOldRoute:(BOOL)doesNewRouteResembleOldOne
                                           alternativeRoutes:(nullable NSArray<NMRoute *> *)alternativeRoutes;

The rerouting by traffic engine may create a new instance of NMRoute class. The newRoute parameter will have non-null value if that happens. The doesNewRouteResembleOldOne parameter indicates whether the route, being navigated after the rerouting by traffic occurred, is identical (takes the same roads) to the route being navigated before rerouting. So if the newRoute is non-nil but the doesNewRouteResembleOldOne is YES means that the route being navigated hasn't changed (takes the same roads).

The alternativeRoutes parameter is a list of alternative routes with the latest traffic applied, which can be used for navigation. Use startNavigatingTheRoute: method to start navigation along one of the alternative routes.


GUIDANCE

Navmii SDK allows you to setup the way the navigation guidance will be provided. It's possible throughout the NMRouteNavigator's instance property guidanceSettings. You can set the guidance output either to text or switch it off. If you pass NMGuidanceOutputText to the NMGuidanceSettings's property guidanceOutput, you'll be able to receive NSString instances with navigation guidance in NMNavigationListener - (void)onGuidanceTextReady:(NSString *)guidanceText method.

- (void)onGuidanceTextReady:(NSString *)guidanceText {

   NSLog(guidanceText);

}

You can also set guidance language via the NMGuidanceSettings's locale property. To get the list of all languages supported by the SDK use the supportedLocales property.
// Sets guidance language to American English
NMGuidanceSettings *settings = navigator.guidanceSettings;
settings.locale = @"en-US";

Currently supported languages:

Voice guidance

It's also possible to receive voice guidance instructions. To do this, first set the path to the directory containing the voice packs by using the NMConfigurationSettings property voicePacksPath. After initialising the SDK, you can retrieve the list of available voice packs with the NMGuidanceSettings availableVoicePacks property, and select one using NMGuidanceSettings voicePack. By passing NMGuidanceOutputVoice to the NMGuidanceSettings guidanceOutput property, directions will be announced using the chosen voice pack.

Example:

- (void)configureSDK {

	//Setup Voice Resources here.

 	NMConfigurationSettings *configurationSettings = [NMConfigurationSettings new];
	configurationSettings.voicePacksPath = [[NSBundle mainBundle] URLForResource:@"VoicePacksFolder" withExtension:nil].path;
}

- (void)setVoiceGuidance {
	
	//Request available voice packs and pass selected one to settings.
	
	NMRouteNavigator *navigator = navmiiSDK.routeNavigator;
	NMGuidanceSettings *guidanceSettings = navigator.guidanceSettings;

	NSArray<NMVoicePack *> *voicePacks = guidanceSettings.availableVoicePacks;
    
	if ([voicePacks count] > 0) {
		NMVoicePack *voicePack = ...// select voice pack here
        guidanceSettings.voicePack = voicePacks;
        guidanceSettings.guidanceOutput = NMGuidanceOutputVoice;
    }
}