See the Mapbox Directions API documentation for more information.
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
)
An sf
object (or list of sf
objects), or full R list representing
the API response.
An input dataset of class "sf"
, or a list of coordinate
pairs for format c(longitude, latitude)
. Cannot be used with an
origin/destination pair.
An address or coordinate pair that represents the origin of
your requested route. Cannot be used with input_data
.
An address or coordinate pair that represents the destination of your requested route.
One of "driving" (the default), "driving-traffic", "walking", or "cycling".
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.
(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"
.
Whether or not to return alternative routes with your request. If TRUE, a list of up to 3 possible routes will be returned.
A comma-separated string of additional route metadata, which may include duration, distance, speed, and congestion. Must be used with overview = "full".
A semicolon-delimited character string of bearings
continue_straight
Road types to exclude from your route; possible choices are
'toll'
, 'motorway'
, or 'ferry'
. Defaults to NULL
.
The route geometry format. If output = 'sf'
, you will get
back an sf
object and you should leave this blank. If output = 'full'
,
the embedded route geometries will be one of 'geojson'
(the default),
'polyline'
with five decimal place precision, or 'polyline6'
.
If left blank, defaults to 'simplified'
for simplified
geometry; the other option is 'full'
which provides the most detailed
geometry available.
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
.
A character string with semicolon-separated specifications
for how to approach waypoints. Options include unrestricted
and curb
.
Defaults to NULL
which uses unrestricted
for all waypoints.
If TRUE
, returns the route object split up into route legs
with step-by-step instructions included. If FALSE
or NULL
(the
default), a single line geometry representing the full route will be
returned.
Whether or not to return banner objects; only
available whenoutput = 'full'
and steps = TRUE
.
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
.
If TRUE, adds instructions for roundabout entrance
and exit. Only available when steps = TRUE
.
Only available when steps = TRUE
and
output = 'full'
.
Only available when steps = TRUE
and output = 'full'
.
The walking speed in meters/second; available when
profile = 'walking'
.
Can take values between -1 and 1, where negative numbers
avoid walkways and positive numbers prefer walkways. Available when
profile = 'walking'
.
Can take values between -1 and 1, where negative numbers
avoid alleys and positive numbers prefer alleys. Available when profile = 'walking'
.
A Mapbox access token; which can be set with
mb_access_token()
if (FALSE) {
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()
}
Run the code above in your browser using DataLab