See the Mapbox Directions API documentation for more information.
Usage
mb_directions(
input_data = NULL,
origin = NULL,
destination = NULL,
profile = "driving",
output = "sf",
depart_at = NULL,
alternatives = NULL,
annotations = NULL,
bearings = NULL,
continue_straight = NULL,
exclude = NULL,
geometries = "geojson",
overview = "simplified",
radiuses = NULL,
approaches = NULL,
steps = NULL,
banner_instructions = NULL,
language = NULL,
roundabout_exits = NULL,
voice_instructions = NULL,
voice_units = NULL,
waypoint_names = NULL,
waypoint_targets = NULL,
waypoints = NULL,
walking_speed = NULL,
walkway_bias = NULL,
alley_bias = NULL,
access_token = NULL
)
Arguments
- input_data
An input dataset of class
"sf"
, or a list of coordinate pairs for formatc(longitude, latitude)
. Cannot be used with an origin/destination pair.- origin
An address or coordinate pair that represents the origin of your requested route. Cannot be used with
input_data
.- destination
An address or coordinate pair that represents the destination of your requested route.
- profile
One of "driving" (the default), "driving-traffic", "walking", or "cycling".
- output
One of "sf" (the default), which returns an sf LINESTRING representing the route geometry, or "full", which returns the full request from the Directions API as a list.
- depart_at
(optional) For the "driving" or "driving-traffic" profiles, the departure date and time to reflect historical traffic patterns. If "driving-traffic" is used, live traffic will be mixed in with historical traffic for dates/times near to the current time. Should be specified as an ISO 8601 date/time, e.g.
"2022-03-31T09:00"
.- alternatives
Whether or not to return alternative routes with your request. If TRUE, a list of up to 3 possible routes will be returned.
- annotations
A comma-separated string of additional route metadata, which may include duration, distance, speed, and congestion. Must be used with overview = "full".
- bearings
A semicolon-delimited character string of bearings
- continue_straight
continue_straight
- exclude
Road types to exclude from your route; possible choices are
'toll'
,'motorway'
, or'ferry'
. Defaults toNULL
.- geometries
The route geometry format. If
output = 'sf'
, you will get back ansf
object and you should leave this blank. Ifoutput = 'full'
, the embedded route geometries will be one of'geojson'
(the default),'polyline'
with five decimal place precision, or'polyline6'
.- overview
If left blank, defaults to
'simplified'
for simplified geometry; the other option is'full'
which provides the most detailed geometry available.- radiuses
A character string with semicolon-separated radii that specify the distance (in meters) to snap each input coordinate to the road network. Defaults to
NULL
.- approaches
A character string with semicolon-separated specifications for how to approach waypoints. Options include
unrestricted
andcurb
. Defaults toNULL
which usesunrestricted
for all waypoints.- steps
If
TRUE
, returns the route object split up into route legs with step-by-step instructions included. IfFALSE
orNULL
(the default), a single line geometry representing the full route will be returned.Whether or not to return banner objects; only available when
output = 'full'
andsteps = TRUE
.- language
The language of the returned instructions (defaults to English). Available language codes are found at https://docs.mapbox.com/api/navigation/#instructions-languages. Only available when
steps = TRUE
.- roundabout_exits
If TRUE, adds instructions for roundabout entrance and exit. Only available when
steps = TRUE
.- voice_instructions, voice_units
Only available when
steps = TRUE
andoutput = 'full'
.- waypoint_names, waypoint_targets, waypoints
Only available when
steps = TRUE
andoutput = 'full'
.- walking_speed
The walking speed in meters/second; available when
profile = 'walking'
.- walkway_bias
Can take values between -1 and 1, where negative numbers avoid walkways and positive numbers prefer walkways. Available when
profile = 'walking'
.- alley_bias
Can take values between -1 and 1, where negative numbers avoid alleys and positive numbers prefer alleys. Available when
profile = 'walking'
.- access_token
A Mapbox access token; which can be set with
mb_access_token()
Examples
if (FALSE) { # \dontrun{
library(mapboxapi)
library(leaflet)
my_route <- mb_directions(
origin = "10 Avenue de Wagram, 75008 Paris France",
destination = "59 Rue de Tocqueville, 75017 Paris France",
profile = "cycling",
steps = TRUE,
language = "fr"
)
leaflet(my_route) %>%
addMapboxTiles(
style_id = "light-v9",
username = "mapbox"
) %>%
addPolylines()
} # }