public class MapboxNavigation extends java.lang.Object implements ProgressChangeListener
| Constructor and Description |
|---|
MapboxNavigation(android.content.Context context,
java.lang.String accessToken)
Creates a new MapboxNavigation object.
|
MapboxNavigation(android.content.Context context,
java.lang.String accessToken,
MapboxNavigationOptions options)
Creates a new MapboxNavigation object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAlertLevelChangeListener(AlertLevelChangeListener alertLevelChangeListener)
Optionally, setup a alert change listener which will be notified when the user reaches a particular part of the
route.
|
void |
addNavigationEventListener(NavigationEventListener navigationEventListener)
Optionally listen into when a new navigation event occurs.
|
void |
addOffRouteListener(OffRouteListener offRouteListener) |
void |
addProgressChangeListener(ProgressChangeListener progressChangeListener)
Optionally, setup a progress change listener to be notified each time the users location has changed.
|
void |
endNavigation()
Call this method to end a navigation session before the user reaches their destination.
|
com.mapbox.services.commons.models.Position |
getDestination()
Get the current destination
Position that will be used for the end of the route. |
MapboxNavigationOptions |
getMapboxNavigationOptions()
Get the currently used
MapboxNavigationOptions, if one isn't set, the default values will be used. |
com.mapbox.services.commons.models.Position |
getOrigin()
Get the current origin
Position that will be used for the beginning of the route. |
void |
getRoute(com.mapbox.services.commons.models.Position origin,
com.mapbox.services.commons.models.Position destination,
retrofit2.Callback<com.mapbox.services.api.directions.v5.models.DirectionsResponse> callback)
Request navigation to acquire a route and notify your callback when a response comes in.
|
void |
getRoute(com.mapbox.services.commons.models.Position origin,
com.mapbox.services.commons.models.Position destination,
java.lang.Float userBearing,
retrofit2.Callback<com.mapbox.services.api.directions.v5.models.DirectionsResponse> callback)
Request navigation to acquire a route and notify your callback when a response comes in.
|
float |
getUserOriginBearing()
Gets the current user bearing that will be used when
getRoute(Position, Position, Callback)'s called. |
void |
onDestroy() |
void |
onProgressChange(android.location.Location location,
RouteProgress routeProgress) |
void |
onStart()
It's required to include both the
onStop and onStart inside your navigation activities identically
named lifecycle methods. |
void |
onStop()
It's required to include both the
onStop and onStart inside your navigation activities identically
named lifecycle methods. |
void |
removeAlertLevelChangeListener(AlertLevelChangeListener alertLevelChangeListener) |
void |
removeNavigationEventListener(NavigationEventListener navigationEventListener) |
void |
removeOffRouteListener(OffRouteListener offRouteListener) |
void |
removeProgressChangeListener(ProgressChangeListener progressChangeListener) |
void |
setLocationEngine(com.mapbox.services.android.telemetry.location.LocationEngine locationEngine)
Before starting a navigationService, it is required to setup a
LocationEngine and pass it into your
instance of MapboxNavigation. |
void |
setSnapToRoute(boolean snapToRoute)
Disable or enable the snap to route for navigation, by default this is set to enable.
|
void |
setupNotification(android.app.Activity activity)
Optionally, set up navigation notification using the default builder provided in the SDK.
|
void |
setUserOriginBearing(float userBearing)
Optional but recommended parameter that can be used to route a user in the correct orientation they are already
headed in.
|
void |
startNavigation(com.mapbox.services.api.directions.v5.models.DirectionsRoute route)
Call
startNavigation passing in a DirectionsRoute object to begin a navigation session. |
void |
updateRoute(com.mapbox.services.api.directions.v5.models.DirectionsRoute directionsRoute)
When a reroute's performed, use this API to pass in the new directions route.
|
public MapboxNavigation(@NonNull
android.content.Context context,
@NonNull
java.lang.String accessToken)
context - Context used for various things internally, cannot be null.accessToken - A valid Mapbox access token.public MapboxNavigation(@NonNull
android.content.Context context,
@NonNull
java.lang.String accessToken,
@NonNull
MapboxNavigationOptions options)
context - Context used for various things internally, cannot be null.accessToken - A valid Mapbox access token.options - a MapboxNavigationOptions with your customized options.public void onStart()
onStop and onStart inside your navigation activities identically
named lifecycle methods.public void onStop()
onStop and onStart inside your navigation activities identically
named lifecycle methods.public void onProgressChange(android.location.Location location,
RouteProgress routeProgress)
onProgressChange in interface ProgressChangeListenerpublic void onDestroy()
public void setLocationEngine(com.mapbox.services.android.telemetry.location.LocationEngine locationEngine)
LocationEngine and pass it into your
instance of MapboxNavigation. If a locationEngine isn't provided, one will be created.locationEngine - A LocationEngine used for the navigation session.public void addNavigationEventListener(NavigationEventListener navigationEventListener)
navigationEventListener - a new NavigationEventListener which will be notified when navigation events
occur.public void removeNavigationEventListener(NavigationEventListener navigationEventListener)
public void addAlertLevelChangeListener(AlertLevelChangeListener alertLevelChangeListener)
alertLevelChangeListener - a new AlertLevelChangeListener which will be notified when event occurs.public void removeAlertLevelChangeListener(AlertLevelChangeListener alertLevelChangeListener)
public void addProgressChangeListener(ProgressChangeListener progressChangeListener)
ProgressChangeListener.progressChangeListener - a new ProgressChangeListener which will be notified when event occurs.public void removeProgressChangeListener(ProgressChangeListener progressChangeListener)
public void addOffRouteListener(OffRouteListener offRouteListener)
public void removeOffRouteListener(OffRouteListener offRouteListener)
public void setSnapToRoute(boolean snapToRoute)
snapToRoute - boolean true if you'd like snap to route be enabled, else false; defaults true.public void startNavigation(com.mapbox.services.api.directions.v5.models.DirectionsRoute route)
startNavigation passing in a DirectionsRoute object to begin a navigation session. It is
recommend to call getRoute(Position, Position, Callback) before starting a navigation
session.route - A DirectionsRoute that makes up the path your user will traverse along.public void updateRoute(com.mapbox.services.api.directions.v5.models.DirectionsRoute directionsRoute)
directionsRoute - the new DirectionsRoutepublic void endNavigation()
addAlertLevelChangeListener(AlertLevelChangeListener) to be notified when the user
arrives at their location.public void setupNotification(android.app.Activity activity)
addAlertLevelChangeListener(AlertLevelChangeListener) to correctly time your
notifications.activity - The activity being used for the navigation session.public void getRoute(com.mapbox.services.commons.models.Position origin,
com.mapbox.services.commons.models.Position destination,
retrofit2.Callback<com.mapbox.services.api.directions.v5.models.DirectionsResponse> callback)
NavigationException will be thrown if you haven't set your access token, origin or destination before
calling getRoute. It's advised to pass in the users bearing whenever possible for a more accurate
directions route.
If you'd like navigation to reroute when the user goes off-route, call this method with the updated information.
callback - A callback of type DirectionsResponse which allows you to handle the Directions API
response.origin - the starting position for the navigation sessiondestination - the arrival position for the navigation sessionpublic void getRoute(com.mapbox.services.commons.models.Position origin,
com.mapbox.services.commons.models.Position destination,
java.lang.Float userBearing,
retrofit2.Callback<com.mapbox.services.api.directions.v5.models.DirectionsResponse> callback)
throws NavigationException
NavigationException will be thrown if you haven't set your access token, origin or destination before
calling getRoute.callback - A callback of type DirectionsResponse which allows you to handle the Directions API
response.origin - the starting position for the navigation sessiondestination - the arrival position for the navigation sessionuserBearing - provide the users bearing to continue the route in the users directionNavigationExceptionpublic com.mapbox.services.commons.models.Position getOrigin()
Position that will be used for the beginning of the route. If no origin's provided,
null will be returned. An origin can be set using the
getRoute(Position, Position, Callback) method.Position object representing the origin of your route.public com.mapbox.services.commons.models.Position getDestination()
Position that will be used for the end of the route. If no destinations's
provided, null will be returned. A destination can be set using the
getRoute(Position, Position, Callback) method.Position object representing the destination of your route.public void setUserOriginBearing(float userBearing)
userBearing - int between 0 and 260 representing the users current bearing.public float getUserOriginBearing()
getRoute(Position, Position, Callback)'s called. If no value's set, the return value will
be null.public MapboxNavigationOptions getMapboxNavigationOptions()
MapboxNavigationOptions, if one isn't set, the default values will be used.