public static final class NavigationRoute.Builder extends Object
By default, the directions profile is set to driving with traffic but can be changed to reflect your users use-case.
Modifier and Type | Method and Description |
---|---|
NavigationRoute.Builder |
accessToken(String accessToken)
Required to call when this is being built.
|
NavigationRoute.Builder |
addApproaches(String... approaches)
Indicates from which side of the road to approach a waypoint.
|
NavigationRoute.Builder |
addBearing(Double angle,
Double tolerance)
Optionally, Use to filter the road segment the waypoint will be placed on by direction and
dictates the angle of approach.
|
NavigationRoute.Builder |
addWaypoint(com.mapbox.geojson.Point waypoint)
This can be used to set up to 23 additional in-between points which will act as pit-stops
along the users route.
|
NavigationRoute.Builder |
addWaypoint(com.mapbox.geojson.Point waypoint,
Double angle,
Double tolerance)
This can be used to set up to 23 additional in-between points which will act as pit-stops
along the users route.
|
NavigationRoute.Builder |
addWaypointIndices(Integer... indices)
Optionally, set which input coordinates should be treated as waypoints / separate legs.
|
NavigationRoute.Builder |
addWaypointNames(String... waypointNames)
Custom names for waypoints used for the arrival instruction,
each separated by ;.
|
NavigationRoute.Builder |
addWaypointTargets(com.mapbox.geojson.Point... waypointTargets)
A list of coordinate pairs used to specify drop-off
locations that are distinct from the locations specified in coordinates.
|
NavigationRoute.Builder |
alternatives(Boolean alternatives)
Optionally set whether to try to return alternative routes.
|
NavigationRoute.Builder |
annotations(String... annotations)
Whether or not to return additional metadata along the route.
|
NavigationRoute.Builder |
baseUrl(String baseUrl)
Optionally change the APIs base URL to something other then the default Mapbox one.
|
NavigationRoute |
build()
This uses the provided parameters set using the
NavigationRoute.Builder and adds the required
settings for navigation to work correctly. |
NavigationRoute.Builder |
clientAppName(String clientAppName)
Base package name or other simple string identifier.
|
NavigationRoute.Builder |
continueStraight(boolean continueStraight)
Sets allowed direction of travel when departing intermediate waypoints.
|
NavigationRoute.Builder |
destination(com.mapbox.geojson.Point destination)
This sets the ending point on the map where the route will end.
|
NavigationRoute.Builder |
destination(com.mapbox.geojson.Point destination,
Double angle,
Double tolerance)
This sets the ending point on the map where the route will end.
|
NavigationRoute.Builder |
enableRefresh(boolean enableRefresh)
Enables a route to be refreshable
|
NavigationRoute.Builder |
eventListener(okhttp3.EventListener eventListener)
Adds an optional event listener to set in the OkHttp client.
|
NavigationRoute.Builder |
exclude(String exclude)
Exclude specific road classes such as highways, tolls, and more.
|
NavigationRoute.Builder |
interceptor(okhttp3.Interceptor interceptor)
Adds an optional interceptor to set in the OkHttp client.
|
NavigationRoute.Builder |
language(Locale language)
Set the instruction language for the directions request, the default is english.
|
NavigationRoute.Builder |
origin(com.mapbox.geojson.Point origin)
This sets the starting point on the map where the route will begin.
|
NavigationRoute.Builder |
origin(com.mapbox.geojson.Point origin,
Double angle,
Double tolerance)
This sets the starting point on the map where the route will begin.
|
NavigationRoute.Builder |
profile(String profile)
This selects which mode of transportation the user will be using while navigating from the
origin to the final destination.
|
NavigationRoute.Builder |
radiuses(double... radiuses)
Optionally, set the maximum distance in meters that each coordinate is allowed to move when
snapped to a nearby road segment.
|
NavigationRoute.Builder |
routeOptions(com.mapbox.api.directions.v5.models.RouteOptions options)
Optionally create a
NavigationRoute.Builder based on all variables
from given RouteOptions . |
NavigationRoute.Builder |
user(String user)
The username for the account that the directions engine runs on.
|
NavigationRoute.Builder |
voiceUnits(String voiceUnits)
Change the units used for voice announcements, this does not change the units provided in
other fields outside of the
VoiceInstructions
object. |
public NavigationRoute.Builder user(@NonNull String user)
DirectionsCriteria.PROFILE_DEFAULT_USER
.user
- a non-null string which will replace the default user used in the directions
requestpublic NavigationRoute.Builder profile(@NonNull String profile)
profile
- required to be one of the String values found in the DirectionsCriteria.ProfileCriteria
public NavigationRoute.Builder origin(@NonNull com.mapbox.geojson.Point origin)
origin
- a GeoJson Point
object representing the starting location for the routepublic NavigationRoute.Builder origin(@NonNull com.mapbox.geojson.Point origin, @Nullable Double angle, @Nullable Double tolerance)
origin
- a GeoJson Point
object representing the starting location for the
routeangle
- double value used for setting the corresponding coordinate's angle of travel
when determining the routetolerance
- the deviation the bearing angle can vary while determining the route,
recommended to be either 45 or 90 degree tolerancepublic NavigationRoute.Builder destination(@NonNull com.mapbox.geojson.Point destination)
destination
- a GeoJson Point
object representing the starting location for the
routepublic NavigationRoute.Builder destination(@NonNull com.mapbox.geojson.Point destination, @Nullable Double angle, @Nullable Double tolerance)
destination
- a GeoJson Point
object representing the starting location for the
routeangle
- double value used for setting the corresponding coordinate's angle of travel
when determining the routetolerance
- the deviation the bearing angle can vary while determining the route,
recommended to be either 45 or 90 degree tolerancepublic NavigationRoute.Builder addWaypoint(@NonNull com.mapbox.geojson.Point waypoint)
DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
that the max number of waypoints allowed
in the request is currently limited to 1.waypoint
- a Point
which represents the pit-stop or waypoint where you'd like
one of the RouteLeg
to
navigate the user topublic NavigationRoute.Builder addWaypoint(@NonNull com.mapbox.geojson.Point waypoint, @Nullable Double angle, @Nullable Double tolerance)
DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
that the max number of waypoints allowed
in the request is currently limited to 1.waypoint
- a Point
which represents the pit-stop or waypoint where you'd like
one of the RouteLeg
to
navigate the user toangle
- double value used for setting the corresponding coordinate's angle of travel
when determining the routetolerance
- the deviation the bearing angle can vary while determining the route,
recommended to be either 45 or 90 degree tolerancepublic NavigationRoute.Builder alternatives(@Nullable Boolean alternatives)
alternatives
- true if you'd like to receive an alternative route, otherwise false or
null to use the APIs default valuepublic NavigationRoute.Builder language(Locale language)
language
- a Locale representing the language you'd like the instructions to be
written in when returnedpublic NavigationRoute.Builder annotations(@Nullable String... annotations)
DirectionsCriteria.ANNOTATION_DISTANCE
,
DirectionsCriteria.ANNOTATION_DURATION
,
DirectionsCriteria.ANNOTATION_DURATION
and
DirectionsCriteria.ANNOTATION_CONGESTION
. Several annotation can be used by
separating them with ,
.
If left alone, this will automatically set Congestion to enabled
annotations
- string referencing one of the annotation direction criteria's. The strings
restricted to one or multiple values inside the DirectionsCriteria.AnnotationCriteria
or null which will result in no annotations being usedpublic NavigationRoute.Builder addBearing(@Nullable Double angle, @Nullable Double tolerance)
radiuses(double...)
parameter.
The parameter takes two values per waypoint: the first is an angle clockwise from true north between 0 and 360. The second is the range of degrees the angle can deviate by. We recommend a value of 45 degrees or 90 degrees for the range, as bearing measurements tend to be inaccurate. This is useful for making sure we reroute vehicles on new routes that continue traveling in their current direction. A request that does this would provide bearing and radius values for the first waypoint and leave the remaining values empty. If provided, the list of bearings must be the same length as the list of waypoints, but you can skip a coordinate and show its position by passing in null value for both the angle and tolerance values.
Each bearing value gets associated with the same order which coordinates are arranged in this
builder. For example, the first bearing added in this builder will be associated with the
origin Point
, the nth bearing being associated with the nth waypoint added (if added)
and the last bearing being added will be associated with the destination.
If given the chance, you should pass in the bearing information at the same time the point is passed in as a waypoint, this way it is ensured the value is matched up correctly with the coordinate.
angle
- double value used for setting the corresponding coordinate's angle of travel
when determining the routetolerance
- the deviation the bearing angle can vary while determining the route,
recommended to be either 45 or 90 degree tolerancepublic NavigationRoute.Builder radiuses(double... radiuses)
Double.POSITIVE_INFINITY
.
If no routable road is found within the radius, a NoSegment
error is returned.
radiuses
- double array containing the radiuses defined in unit meters.public NavigationRoute.Builder voiceUnits(String voiceUnits)
VoiceInstructions
object.voiceUnits
- one of the values found inside the DirectionsCriteria.VoiceUnitCriteria
public NavigationRoute.Builder exclude(@Nullable String exclude)
exclude
- one of the values found inside the DirectionsCriteria.ExcludeCriteria
public NavigationRoute.Builder clientAppName(@NonNull String clientAppName)
clientAppName
- base package name or other simple string identifierpublic NavigationRoute.Builder accessToken(@NonNull String accessToken)
ServicesException
will be thrown.accessToken
- Mapbox access token, You must have a Mapbox account inorder to use
the Optimization APIpublic NavigationRoute.Builder baseUrl(String baseUrl)
baseUrl
- base url used as end pointpublic NavigationRoute.Builder addApproaches(String... approaches)
approaches
- null if you'd like the default approaches,
else one of the options found in
DirectionsCriteria.ApproachesCriteria
.public NavigationRoute.Builder addWaypointIndices(@Nullable Integer... indices)
Most useful in combination with steps=true and requests based on traces with high sample rates. Can be an index corresponding to any of the input coordinates, but must contain the first ( 0 ) and last coordinates' index separated by ;.
indices
- integer array of coordinate indices to be used as waypointspublic NavigationRoute.Builder addWaypointNames(@Nullable String... waypointNames)
waypointNames
- Custom names for waypoints used for the arrival instruction.public NavigationRoute.Builder addWaypointTargets(@Nullable com.mapbox.geojson.Point... waypointTargets)
waypointTargets
- Point
coordinates for drop-off locationspublic NavigationRoute.Builder interceptor(okhttp3.Interceptor interceptor)
interceptor
- to set for OkHttppublic NavigationRoute.Builder eventListener(okhttp3.EventListener eventListener)
eventListener
- to set for OkHttppublic NavigationRoute.Builder enableRefresh(boolean enableRefresh)
enableRefresh
- whether or not to enable refreshpublic NavigationRoute.Builder continueStraight(boolean continueStraight)
DirectionsCriteria.PROFILE_DRIVING
and false for
DirectionsCriteria.PROFILE_WALKING
and DirectionsCriteria.PROFILE_CYCLING
.continueStraight
- boolean true if you want to always continue straight, else false.public NavigationRoute.Builder routeOptions(com.mapbox.api.directions.v5.models.RouteOptions options)
NavigationRoute.Builder
based on all variables
from given RouteOptions
.
Note: RouteOptions.bearings()
are excluded because it's better
to recalculate these at the time of the request, as your location bearing
is constantly changing.
options
- containing all variables for requestpublic NavigationRoute build()
NavigationRoute.Builder
and adds the required
settings for navigation to work correctly.© 2019 Mapbox. All rights reserved.