Navigator

public interface Navigator

A singleton which provides methods for controlling navigation.

All methods are guaranteed to be thread-safe except for setAudioGuidance and setHeadsUpNotificationEnabled which must be called on the UI thread.

Nested Class Summary

interface Navigator.ArrivalListener Defines signatures for methods that are called when the driver arrives at a waypoint. 
@interface Navigator.AudioGuidance AudioGuidance is a set of flags used to specify what kinds of audio alerts and guidance are used during navigation. 
interface Navigator.NavigationSessionListener Defines signatures for methods that are called when a new navigation session starts. 
interface Navigator.RemainingTimeOrDistanceChangedListener Defines signatures for methods that are called when the remaining time or distance to the next destination changes. 
interface Navigator.RouteChangedListener Defines signatures for methods that are called when the route changes. 
enum Navigator.RouteStatus A RouteStatus is a status code that represents the result of a route calculation, accessed via the Future returned by Navigator.setDestination(Waypoint)

Constant Summary

int MAX_NUM_TRANSACTION_IDS
int MAX_TRANSACTION_ID_LENGTH

Public Method Summary

abstract void
addArrivalListener(Navigator.ArrivalListener listener)
Registers a listener for arrival events.
abstract void
addNavigationSessionListener(Navigator.NavigationSessionListener listener)
Registers a listener for new navigation sessions.
abstract void
addRemainingTimeOrDistanceChangedListener(int timeChangeThresholdSeconds, int distanceChangeThresholdMeters, Navigator.RemainingTimeOrDistanceChangedListener listener)
Registers a listener for when the remaining time or distance to the destination changes by more than a specified threshold.
abstract void
addRouteChangedListener(Navigator.RouteChangedListener listener)
Registers a listener for route changed events.
abstract void
cleanup()
Cleans up internal state of the Navigator.
abstract void
clearDestinations()
Clears all previously set destinations and removes any calculated routes from the map.
abstract void
clearLicensePlateRestrictionInfo()
Clears license plate information about the current driver.
abstract void
abstract Waypoint
continueToNextDestination()
Removes the current destination.
abstract ListenableResultFuture<RouteInfo>
fetchRouteInfo(Waypoint waypoint, RoutingOptions routingOptions)
Returns route information for routes based on each value of RoutingOptions.RoutingStrategy.
abstract RouteSegment
getCurrentRouteSegment()
Returns the current segment of the journey.
abstract TimeAndDistance
getCurrentTimeAndDistance()
Returns the estimated time and distance from the current position to the current destination.
abstract List<RouteSegment>
getRouteSegments()
Returns a list of route segments.
abstract Simulator
getSimulator()
Returns a Simulator object, for use during testing.
abstract List<TimeAndDistance>
getTimeAndDistanceList()
Returns a list of times and distances corresponding to each destination in the current route, representing the estimated time and distance from the current position to each destination.
abstract List<LatLng>
getTraveledRoute()
Returns the route traveled so far during this guidance session (since the last call to startGuidance()).
abstract boolean
isGuidanceRunning()
Returns true if guidance is currently running.
abstract void
abstract void
abstract void
abstract void
abstract void
setArrivalListener(Navigator.ArrivalListener listener)
This method is deprecated. Use addArrivalListener(ArrivalListener) to set one or more listeners and removeArrivalListener(ArrivalListener) to remove them to avoid memory leaks.
abstract void
setAudioGuidance(int guidance)
Sets which types of audio guidance (including vibration) are enabled.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestination(Waypoint destination, RoutingOptions routingOptions, DisplayOptions displayOptions)
Sets a single destination for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestination(Waypoint destination, RoutingOptions options)
Sets a single destination for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestination(Waypoint destination)
Sets a single destination for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, RoutingOptions options)
Sets multiple destinations for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, String routeToken)
This method is deprecated. Instead, call setDestinations(destinations, customRoutesOptions).
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, CustomRoutesOptions customRoutesOptions, DisplayOptions displayOptions)
Sets destinations for navigation using a route token to navigate on a precomputed route using CustomRoutesOptions, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, RoutingOptions routingOptions, DisplayOptions displayOptions)
Sets multiple destinations for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations)
Sets multiple destinations for navigation, overriding any previously set destinations.
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, String routeToken, DisplayOptions displayOptions)
This method is deprecated. Instead, call setDestinations(destinations, customRoutesOptions, displayOptions).
abstract ListenableResultFuture<Navigator.RouteStatus>
setDestinations(List<Waypoint> destinations, CustomRoutesOptions customRoutesOptions)
Sets destinations for navigation using a route token to navigate on a precomputed route using CustomRoutesOptions, overriding any previously set destinations.
abstract void
setHeadsUpNotificationEnabled(boolean enabled)
Sets whether heads-up notifications should be shown.
abstract void
setLicensePlateRestrictionInfo(int rawLicensePlateLastDigit, String licensePlateCountryCode)
Sets license plate information about the current driver.
abstract void
setRemainingTimeOrDistanceChangedListener(int timeChangeThresholdSeconds, int distanceChangeThresholdMeters, Navigator.RemainingTimeOrDistanceChangedListener listener)
abstract void
setRouteChangedListener(Navigator.RouteChangedListener listener)
This method is deprecated. Use addRouteChangedListener(RouteChangedListener) to set one or more listeners and removeRouteChangedListener(RouteChangedListener) to remove them to avoid memory leaks.
abstract void
setSpeedAlertOptions(SpeedAlertOptions speedAlertOptions)
Sets SpeedAlertOptions for customizing the triggering thresholds for SpeedAlertSeveritys.
abstract void
setSpeedingListener(SpeedingListener speedingListener)
Registers a SpeedingListener for the percentage above the speed limit the driver is currently driving at.
abstract void
setTransactionIds(List<String> transactionIds)
Sets the ongoing transaction IDs.
abstract void
startGuidance(Intent resumeIntent)
This method is deprecated. Recommend setting resume intent via NavigationApi.initForegroundServiceManagerMessageAndIntent(Application, Integer, String, Intent).
abstract void
startGuidance()
If a destination has been set and a route computed for it, starts turn-by-turn navigation guidance for the route.
abstract void
stopGuidance()
Stops turn-by-turn navigation guidance.

Constants

public static final int MAX_NUM_TRANSACTION_IDS

Constant Value: 100

public static final int MAX_TRANSACTION_ID_LENGTH

Constant Value: 64

Public Methods

public abstract void addArrivalListener (Navigator.ArrivalListener listener)

Registers a listener for arrival events.

Note: In order to avoid memory leaks, use removeArrivalListener(ArrivalListener) to remove the listener that is no longer required.

Parameters
listener the listener to register.

public abstract void addNavigationSessionListener (Navigator.NavigationSessionListener listener)

Registers a listener for new navigation sessions.

Note: In order to avoid memory leaks, use removeNavigationSessionListener(NavigationSessionListener) to remove the listener that is no longer required.

Parameters
listener the listener to register.

public abstract void addRemainingTimeOrDistanceChangedListener (int timeChangeThresholdSeconds, int distanceChangeThresholdMeters, Navigator.RemainingTimeOrDistanceChangedListener listener)

Registers a listener for when the remaining time or distance to the destination changes by more than a specified threshold.

The listener could be called as a result of (for example) user movement, a change in traffic conditions OR a change in route OR a change in destination, or when the remaining time and distance first become known.

Note: In order to avoid memory leaks, use removeRemainingTimeOrDistanceChangedListener(RemainingTimeOrDistanceChangedListener) to remove the listener that is no longer required.

Note: Same listener instance can be added with different threshold values however, calling removeRemainingTimeOrDistanceChangedListener(RemainingTimeOrDistanceChangedListener) using that particular instance will remove it altogether.

Parameters
timeChangeThresholdSeconds If the absolute change in the remaining time in seconds is greater than or equal to this value, then the listener is called. This threshold must not be negative.
distanceChangeThresholdMeters If the absolute change in the remaining distance in meters is greater than or equal to this value, then the listener is called. This threshold must not be negative.
listener the listener to register. Must not be null.
Throws
IllegalArgumentException if the listener is null, or timeChangeThresholdSeconds is negative, or distanceChangeThresholdMeters is negative.

public abstract void addRouteChangedListener (Navigator.RouteChangedListener listener)

Registers a listener for route changed events.

Note: In order to avoid memory leaks, use removeRouteChangedListener(RouteChangedListener) to remove the listener that is no longer required.

Parameters
listener the listener to register.

public abstract void cleanup ()

Cleans up internal state of the Navigator.

Note: calling this method will cancel any pending requests to setDestinations(List).

public abstract void clearDestinations ()

Clears all previously set destinations and removes any calculated routes from the map. If navigation is running, this will automatically stop it.

public abstract void clearLicensePlateRestrictionInfo ()

Clears license plate information about the current driver. This will only apply to setDestination calls made after this value is set.

public abstract void clearRemainingTimeOrDistanceChangedListener ()

This method is deprecated.
Use removeRemainingTimeOrDistanceChangedListener(RemainingTimeOrDistanceChangedListener) instead.

Clears the listener for changes in remaining time or distance.

public abstract Waypoint continueToNextDestination ()

Removes the current destination. Following this call, guidance will be toward the next destination, and information about the old destination is not available.

Returns
  • the waypoint guidance is now heading to, or null if there were no more waypoints left

public abstract ListenableResultFuture<RouteInfo> fetchRouteInfo (Waypoint waypoint, RoutingOptions routingOptions)

Returns route information for routes based on each value of RoutingOptions.RoutingStrategy. RoutingOptions.RoutingStrategy is ignored since this method returns the route information for all routing strategies.

Note: This is recalculated on every call and may not match the routes currently being used by navigation since traffic and other factors may have been updated in the interim.

Parameters
waypoint the destination waypoint for the route
routingOptions the options used to fetch the route info
Returns
  • the returned future

public abstract RouteSegment getCurrentRouteSegment ()

Returns the current segment of the journey. This RouteSegment will have its starting position as the most recent known (road-snapped) position of the device.

Returns
  • a route segment object, or null if there is no current route

public abstract TimeAndDistance getCurrentTimeAndDistance ()

Returns the estimated time and distance from the current position to the current destination.

Returns
  • a time and distance object, or null if there is no current route

public abstract List<RouteSegment> getRouteSegments ()

Returns a list of route segments. The destination of each returned segment will correspond to a destination set by setDestination(s).

public abstract Simulator getSimulator ()

Returns a Simulator object, for use during testing.

public abstract List<TimeAndDistance> getTimeAndDistanceList ()

Returns a list of times and distances corresponding to each destination in the current route, representing the estimated time and distance from the current position to each destination.

public abstract List<LatLng> getTraveledRoute ()

Returns the route traveled so far during this guidance session (since the last call to startGuidance()). The route recorded consists of the road-snapped locations as would be returned by the RoadSnappedLocationProvider, and simplified to remove redundant points, for example turning consecutive colinear points into a single line segment.

public abstract boolean isGuidanceRunning ()

Returns true if guidance is currently running. Note that guidance will only run once a route to a destination has been computed and startGuidance() has been called.

public abstract void removeArrivalListener (Navigator.ArrivalListener listener)

Removes a listener added via addArrivalListener(ArrivalListener).

Parameters
listener added via addArrivalListener(ArrivalListener).

public abstract void removeNavigationSessionListener (Navigator.NavigationSessionListener listener)

public abstract void removeRouteChangedListener (Navigator.RouteChangedListener listener)

Removes the listener added via addRouteChangedListener(RouteChangedListener).

Parameters
listener added via addRouteChangedListener(RouteChangedListener).

public abstract void setArrivalListener (Navigator.ArrivalListener listener)

This method is deprecated.
Use addArrivalListener(ArrivalListener) to set one or more listeners and removeArrivalListener(ArrivalListener) to remove them to avoid memory leaks.

Registers a listener for arrival events. Overrides any previously registered listeners.

Note: In order to avoid memory leaks, setNavArrivalListener(null) should be called when the listener is no longer required.

Parameters
listener the listener to register. Can be set to null to clear a previously registered listener.

public abstract void setAudioGuidance (int guidance)

Sets which types of audio guidance (including vibration) are enabled. By default, vibration, voice, and voice over Bluetooth (if available) are enabled.

This method must be called on the UI thread.

Parameters
guidance a combination of Navigator.AudioGuidance flags specifying which types of audio guidance should be enabled

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestination (Waypoint destination, RoutingOptions routingOptions, DisplayOptions displayOptions)

Sets a single destination for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

Parameters
destination the new destination to be set
routingOptions the options that will be used to generate the route
displayOptions the options that will be used to display the route
Returns
  • the returned future
Throws
NullPointerException if the given destination is null

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestination (Waypoint destination, RoutingOptions options)

Sets a single destination for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination. The default DisplayOptions will be used to display the route.

Parameters
destination the new destination to be set
options the options that will be used to generate the route
Returns
  • the returned future
Throws
NullPointerException if the given destination is null

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestination (Waypoint destination)

Sets a single destination for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination. The default RoutingOptions will be used to find the route, and the default DisplayOptions will be used to display it.

Parameters
destination the new destination to be set
Returns
  • the returned future
Throws
NullPointerException if the given destination is null

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, RoutingOptions options)

Sets multiple destinations for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination. The default DisplayOptions will be used to display the route.

Parameters
destinations the new destination list to be set
options the options that will be used to generate the route
Returns
  • the returned future

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, String routeToken)

This method is deprecated.
Instead, call setDestinations(destinations, customRoutesOptions).

Sets destinations for navigation using a route token to navigate on a precomputed route, overriding any previously set destinations. Routes will be the same, modulo changes to the driver starting location and to road/traffic conditions.

The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

The default DisplayOptions will be used to display the route.

Parameters
destinations the new destination list to be set.
routeToken a route token string returned by RoutesPreferred API. Only tokens generated using "DRIVE" travel mode are supported by this function.
Returns
  • a future object with the status of the request.

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, CustomRoutesOptions customRoutesOptions, DisplayOptions displayOptions)

Sets destinations for navigation using a route token to navigate on a precomputed route using CustomRoutesOptions, overriding any previously set destinations. Routes will be the same, modulo changes to the driver starting location and to road/traffic conditions.

The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

Parameters
destinations the new destination list to be set.
customRoutesOptions the options that will be used to retrieve a precomputed route, based on a token returned by the Routes Preferred API.
displayOptions the options that will be used to display the route.
Returns
  • a future object with the status of the request.

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, RoutingOptions routingOptions, DisplayOptions displayOptions)

Sets multiple destinations for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

Parameters
destinations the new destination list to be set
routingOptions the options that will be used to generate the route
displayOptions the options that will be used to display the route
Returns
  • the returned future

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations)

Sets multiple destinations for navigation, overriding any previously set destinations. The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination. The default RoutingOptions will be used to find the route, and the default DisplayOptions will be used to display it.

Parameters
destinations the new destination list to be set
Returns
  • the returned future

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, String routeToken, DisplayOptions displayOptions)

This method is deprecated.
Instead, call setDestinations(destinations, customRoutesOptions, displayOptions).

Sets destinations for navigation using a route token to navigate on a precomputed route, overriding any previously set destinations. Routes will be the same, modulo changes to the driver starting location and to road/traffic conditions.

The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

Parameters
destinations the new destination list to be set.
routeToken a route token string returned by RoutesPreferred API. Only tokens generated using "DRIVE" travel mode are supported by this function.
displayOptions the options that will be used to display the route.
Returns
  • a future object with the status of the request.

public abstract ListenableResultFuture<Navigator.RouteStatus> setDestinations (List<Waypoint> destinations, CustomRoutesOptions customRoutesOptions)

Sets destinations for navigation using a route token to navigate on a precomputed route using CustomRoutesOptions, overriding any previously set destinations. Routes will be the same, modulo changes to the driver starting location and to road/traffic conditions.

The returned future will be set to Navigator.RouteStatus.OK if a route is found from the user's location to the given destination.

The default DisplayOptions will be used to display the route.

Parameters
destinations the new destination list to be set.
customRoutesOptions the options that will be used to retrieve a precomputed route, based on a token returned by the Routes Preferred API.
Returns
  • a future object with the status of the request.

public abstract void setHeadsUpNotificationEnabled (boolean enabled)

Sets whether heads-up notifications should be shown. By default, the notification is enabled. Heads-up events are guidance events such as turns, etc, that are displayed when there is no map visible.

This method must be called on the UI thread.

Parameters
enabled a flag to indicate if heads-up notifications should be enabled

public abstract void setLicensePlateRestrictionInfo (int rawLicensePlateLastDigit, String licensePlateCountryCode)

Sets license plate information about the current driver. This allows us to route around certain types of road restrictions which are based on license plate number. This will only apply to setDestination calls made after this value is set. Ideally you'd call this immediately after getting the navigator.

Parameters
rawLicensePlateLastDigit The last digit of the license plate (must be between 0 and 9).
licensePlateCountryCode Currently we support Indonesia (ID) and Brazil (BZ) others may be supported in the future and you are free to proactively provide this information.

public abstract void setRemainingTimeOrDistanceChangedListener (int timeChangeThresholdSeconds, int distanceChangeThresholdMeters, Navigator.RemainingTimeOrDistanceChangedListener listener)

This method is deprecated.
Use addRemainingTimeOrDistanceChangedListener(int, int, RemainingTimeOrDistanceChangedListener) to set one or more listeners and removeRemainingTimeOrDistanceChangedListener(RemainingTimeOrDistanceChangedListener) to remove them to avoid memory leaks.

Registers a listener for when the remaining time or distance to the destination changes by more than a specified threshold. Overrides any previously registered listeners.

The listener could be called as a result of (for example) user movement, a change in traffic conditions, a change in route, a change in destination, or when the remaining time and distance first become known.

Note: In order to avoid memory leaks, clearNavProgressionListener() should be called when the listener is no longer required.

Parameters
timeChangeThresholdSeconds If the absolute change in the remaining time in seconds is greater than or equal to this value, then the listener is called. This threshold must not be negative.
distanceChangeThresholdMeters If the absolute change in the remaining distance in meters is greater than or equal to this value, then the listener is called. This threshold must not be negative.
listener the listener to register. Must not be null.
Throws
IllegalArgumentException if the listener is null, or timeChangeThresholdSeconds is negative, or distanceChangeThresholdMeters is negative.

public abstract void setRouteChangedListener (Navigator.RouteChangedListener listener)

This method is deprecated.
Use addRouteChangedListener(RouteChangedListener) to set one or more listeners and removeRouteChangedListener(RouteChangedListener) to remove them to avoid memory leaks.

Registers a listener for route changed events. Overrides any previously registered listeners.

Note: In order to avoid memory leaks, setNavRouteChangeListener(null) should be called when the listener is no longer required.

Parameters
listener the listener to register. Can be set to null to clear a previously registered listener.

public abstract void setSpeedAlertOptions (SpeedAlertOptions speedAlertOptions)

Sets SpeedAlertOptions for customizing the triggering thresholds for SpeedAlertSeveritys.

You can use this method to customize the speed alert triggering thresholds in percentage for both SpeedAlertSeverity.MINOR and SpeedAlertSeverity.MAJOR alerts. You can also use this method to configure the time in seconds needed to upgrade speed alerts from SpeedAlertSeverity.MINOR to SpeedAlertSeverity.MAJOR.

By setting a null SpeedAlertOptions or not setting any, you won't receive any speeding feed data, and the NavSDK’s default speed alert will display: speed alert shows red text in white/dark background for day/night mode respectively when the speed is less than 5 mph or 10 kph over the speed limit, and shows white text in red background when speeding more than 5 mph or 10 kph.

The triggering thresholds configured in SpeedAlertOptions are used to decide whether to display minor or major alerts.

Parameters
speedAlertOptions

public abstract void setSpeedingListener (SpeedingListener speedingListener)

Registers a SpeedingListener for the percentage above the speed limit the driver is currently driving at.

By setting a null SpeedingListener or not setting any, you won't receive any speeding feed data.

Parameters
speedingListener

public abstract void setTransactionIds (List<String> transactionIds)

Sets the ongoing transaction IDs. This API should be used when a new navigation session starts (in the Navigator.NavigationSessionListener.onNewNavigationSession()) and when the transaction IDs change in an ongoing navigation session (e.g. when the list of journey segments is updated).

The transactionIds parameter should be populated with unique string identifiers for one or more transactions that apply to the following events during the current navigation.

This will overwrite any transaction IDs set before.

Transaction IDs will be cleared at the end of the navigation session.

Each transaction ID must be at least 1 and at most 64 characters long, and there is a maximum of 100 transaction IDs per call.

Currently this API will only be used by DriverSDK, and should be ignored by other clients.

Parameters
transactionIds one or more transaction IDs to which the following navigation applies. A transaction ID is an arbitrary string that is unique for each billable transaction.
Throws
NavigationTransactionRecorder.TransactionException if the transaction IDs sent are null, more than MAX_NUM_TRANSACTION_IDS or individually longer than MAX_TRANSACTION_ID_LENGTH.

public abstract void startGuidance (Intent resumeIntent)

This method is deprecated.
Recommend setting resume intent via NavigationApi.initForegroundServiceManagerMessageAndIntent(Application, Integer, String, Intent).

The same as startGuidance(), but specifying an intent that can be used to resume the application from the navigator's status bar notification. Without this intent it is not possible to resume the application from the status bar.

Parameters
resumeIntent the intent for resuming the application. In most cases the value returned by android.app.Activity#getIntent() will be suitable.

public abstract void startGuidance ()

If a destination has been set and a route computed for it, starts turn-by-turn navigation guidance for the route. If a route has not yet been computed, turn-by-turn guidance will start once it has.

You must explicitly call stopGuidance() to stop the navigation service. The navigation service will not automatically stop upon arrival. If you want to stop the navigation service upon arrival, you need to call stopGuidance() in the NavArrivalListener.

Note: this method does not change the position of the Camera.

public abstract void stopGuidance ()

Stops turn-by-turn navigation guidance.