RouteOptions
open class RouteOptions: NSObject, NSSecureCoding, NSCopying
A RouteOptions
object is a structure that specifies the criteria for results returned by the Mapbox Directions API.
Pass an instance of this class into the Directions.calculate(_:completionHandler:)
method.
-
Initializes a route options object for routes between the given waypoints and an optional profile identifier.
Declaration
Swift
@objc public init(waypoints: [Waypoint], profileIdentifier: MBDirectionsProfileIdentifier? = nil)
Parameters
waypoints
An array of
Waypoint
objects representing locations that the route should visit in chronological order. The array should contain at least two waypoints (the source and destination) and at most 25 waypoints. (Some profiles, such asMBDirectionsProfileIdentifierAutomobileAvoidingTraffic
, may have lower limits.)profileIdentifier
A string specifying the primary mode of transportation for the routes. This parameter, if set, should be set to
MBDirectionsProfileIdentifierAutomobile
,MBDirectionsProfileIdentifierAutomobileAvoidingTraffic
,MBDirectionsProfileIdentifierCycling
, orMBDirectionsProfileIdentifierWalking
.MBDirectionsProfileIdentifierAutomobile
is used by default. -
Initializes a route options object for routes between the given locations and an optional profile identifier.
Note
This initializer is intended for
CLLocation
objects created using theCLLocation.init(latitude:longitude:)
initializer. If you intend to use aCLLocation
object obtained from aCLLocationManager
object, consider increasing thehorizontalAccuracy
or set it to a negative value to avoid overfitting, since theWaypoint
class’scoordinateAccuracy
property represents the maximum allowed deviation from the waypoint.Declaration
Swift
@objc public convenience init(locations: [CLLocation], profileIdentifier: MBDirectionsProfileIdentifier? = nil)
Parameters
locations
An array of
CLLocation
objects representing locations that the route should visit in chronological order. The array should contain at least two locations (the source and destination) and at most 25 locations. Each location object is converted into aWaypoint
object. This class respects theCLLocation
class’scoordinate
andhorizontalAccuracy
properties, converting them into theWaypoint
class’scoordinate
andcoordinateAccuracy
properties, respectively.profileIdentifier
A string specifying the primary mode of transportation for the routes. This parameter, if set, should be set to
MBDirectionsProfileIdentifierAutomobile
,MBDirectionsProfileIdentifierAutomobileAvoidingTraffic
,MBDirectionsProfileIdentifierCycling
, orMBDirectionsProfileIdentifierWalking
.MBDirectionsProfileIdentifierAutomobile
is used by default. -
Initializes a route options object for routes between the given geographic coordinates and an optional profile identifier.
Declaration
Swift
@objc public convenience init(coordinates: [CLLocationCoordinate2D], profileIdentifier: MBDirectionsProfileIdentifier? = nil)
Parameters
coordinates
An array of geographic coordinates representing locations that the route should visit in chronological order. The array should contain at least two locations (the source and destination) and at most 25 locations. Each coordinate is converted into a
Waypoint
object.profileIdentifier
A string specifying the primary mode of transportation for the routes. This parameter, if set, should be set to
MBDirectionsProfileIdentifierAutomobile
,MBDirectionsProfileIdentifierAutomobileAvoidingTraffic
,MBDirectionsProfileIdentifierCycling
, orMBDirectionsProfileIdentifierWalking
.MBDirectionsProfileIdentifierAutomobile
is used by default.
-
An array of
Waypoint
objects representing locations that the route should visit in chronological order.A waypoint object indicates a location to visit, as well as an optional heading from which to approach the location.
The array should contain at least two waypoints (the source and destination) and at most 25 waypoints.
Declaration
Swift
@objc open var waypoints: [Waypoint]
-
A Boolean value that indicates whether a returned route may require a point U-turn at an intermediate waypoint.
If the value of this property is
true
, a returned route may require an immediate U-turn at an intermediate waypoint. At an intermediate waypoint, if the value of this property isfalse
, each returned route may continue straight ahead or turn to either side but may not U-turn. This property has no effect if only two waypoints are specified.Set this property to
true
if you expect the user to traverse each leg of the trip separately. For example, it would be quite easy for the user to effectively “U-turn” at a waypoint if the user first parks the car and patronizes a restaurant there before embarking on the next leg of the trip. Set this property tofalse
if you expect the user to proceed to the next waypoint immediately upon arrival. For example, if the user only needs to drop off a passenger or package at the waypoint before continuing, it would be inconvenient to perform a U-turn at that location.The default value of this property is
false
when the profile identifier isMBDirectionsProfileIdentifierAutomobile
orMBDirectionsProfileIdentifierAutomobileAvoidingTraffic
andtrue
otherwise.Declaration
Swift
@objc open var allowsUTurnAtWaypoint: Bool
-
A string specifying the primary mode of transportation for the routes.
This property should be set to
MBDirectionsProfileIdentifierAutomobile
,MBDirectionsProfileIdentifierAutomobileAvoidingTraffic
,MBDirectionsProfileIdentifierCycling
, orMBDirectionsProfileIdentifierWalking
. The default value of this property isMBDirectionsProfileIdentifierAutomobile
, which specifies driving directions.Declaration
Swift
@objc open var profileIdentifier: MBDirectionsProfileIdentifier
-
A Boolean value indicating whether alternative routes should be included in the response.
If the value of this property is
false
, the server only calculates a single route that visits each of the waypoints. If the value of this property istrue
, the server attempts to find additional reasonable routes that visit the waypoints. Regardless, multiple routes are only returned if it is possible to visit the waypoints by a different route without significantly increasing the distance or travel time. The alternative routes may partially overlap with the preferred route, especially if intermediate waypoints are specified.Alternative routes may take longer to calculate and make the response significantly larger, so only request alternative routes if you intend to display them to the user or let the user choose them over the preferred route. For example, do not request alternative routes if you only want to know the distance or estimated travel time to a destination.
The default value of this property is
false
.Declaration
Swift
@objc open var includesAlternativeRoutes = false
-
A Boolean value indicating whether
MBRouteStep
objects should be included in the response.If the value of this property is
true
, the returned route contains turn-by-turn instructions. Each returnedMBRoute
object contains one or moreMBRouteLeg
object that in turn contains one or moreMBRouteStep
objects. On the other hand, if the value of this property isfalse
, theMBRouteLeg
objects contain noMBRouteStep
objects.If you only want to know the distance or estimated travel time to a destination, set this property to
false
to minimize the size of the response and the time it takes to calculate the response. If you need to display turn-by-turn instructions, set this property totrue
.The default value of this property is
false
.Declaration
Swift
@objc open var includesSteps = false
-
Format of the data from which the shapes of the returned route and its steps are derived.
This property has no effect on the returned shape objects, although the choice of format can significantly affect the size of the underlying HTTP response.
The default value of this property is
polyline
.Declaration
Swift
@objc open var shapeFormat = RouteShapeFormat.polyline
-
Resolution of the shape of the returned route.
This property has no effect on the shape of the returned route’s steps.
The default value of this property is
low
, specifying a low-resolution route shape.Declaration
Swift
@objc open var routeShapeResolution = RouteShapeResolution.low
-
AttributeOptions for the route. Any combination of
AttributeOptions
can be specified.By default, no attribute options are specified. It is recommended that
routeShapeResolution
be set to.full
.Declaration
Swift
@objc open var attributeOptions: AttributeOptions = []
-
A Boolean value indicating whether the route includes a
ManeuverType.exitRoundabout
orManeuverType.exitRotary
step when traversing a roundabout or rotary, respectively.If this option is set to
true
, a route that traverses a roundabout includes both aManeuverType.takeRoundabout
step and aManeuverType.exitRoundabout
step; likewise, a route that traverses a large, named roundabout includes both aManeuverType.takeRotary
step and aManeuverType.exitRotary
step. Otherwise, it only includes aManeuverType.takeRoundabout
orManeuverType.takeRotary
step. This option is set tofalse
by default.Declaration
Swift
@objc open var includesExitRoundaboutManeuver = false
-
The locale in which the route’s instructions are written.
If you use MapboxDirections.swift with the Mapbox Directions API, this property affects the sentence contained within the
RouteStep.instructions
property, but it does not affect any road names contained in that property or other properties such asRouteStep.name
.The Directions API can provide instructions in a number of languages. Set this property to
Bundle.main.preferredLocalizations.first
orLocale.autoupdatingCurrent
to match the application’s language or the system language, respectively.By default, this property is set to the current system locale.
Declaration
Swift
@objc open var locale = Locale.autoupdatingCurrent
-
A Boolean value indicating whether each route step includes an array of
SpokenInstructions
.If this option is set to true, the
RouteStep.instructionsSpokenAlongStep
property is set to an array ofSpokenInstructions
.Declaration
Swift
@objc open var includesSpokenInstructions = false
-
The measurement system used in spoken instructions included in route steps.
If the
includesSpokenInstructions
property is set totrue
, this property determines the units used for measuring the distance remaining until an upcoming maneuver. If theincludesSpokenInstructions
property is set tofalse
, this property has no effect.You should choose a measurement system appropriate for the current region. You can also allow the user to indicate their preferred measurement system via a setting.
Declaration
Swift
@objc open var distanceMeasurementSystem: MeasurementSystem = Locale.autoupdatingCurrent.usesMetric ? .metric : .imperial
-
The route classes that the calculated routes will avoid.
Currently, you can only specify a single road class to avoid.
Declaration
Swift
@objc open var roadClassesToAvoid: RoadClasses = []