mb_optimized_route | R Documentation |
Return an optimized route for a series of input coordinates
mb_optimized_route(
input_data,
profile = c("driving", "walking", "cycling", "driving-traffic"),
output = "sf",
source = c("any", "first"),
destination = c("any", "last"),
roundtrip = TRUE,
annotations = NULL,
approaches = NULL,
bearings = NULL,
distributions = NULL,
language = NULL,
overview = "simplified",
radiuses = NULL,
steps = NULL,
access_token = NULL
)
input_data |
An input dataset of class |
profile |
One of "driving" (the default), "driving-traffic", "walking", or "cycling". |
output |
One of "sf" (the default), which returns an |
source |
One of |
destination |
One of |
roundtrip |
If |
annotations |
A comma-separated string of additional route metadata,
which may include duration, distance, speed, and congestion. Must be used
with |
approaches |
A character string with semicolon-separated specifications
for how to approach waypoints. Options include |
bearings |
A semicolon-delimited character string of bearings. |
distributions |
A semicolon-delimited character string of number pairs that specifies pick-up and drop-off locations. The first number indicates the index of the pick-up location, and the second number represents the index of the drop-off location. |
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 |
overview |
If left blank, defaults to |
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 |
steps |
If |
access_token |
Your Mapbox access token; which can be set with
|
Either a list of two sf
objects - one representing the waypoints, and one representing the route - or an R list representing the full optimization API response.
## Not run:
library(mapboxapi)
library(sf)
to_visit <- data.frame(
X = c(-0.209307, -0.185875, -0.216877, -0.233511, -0.234541),
Y = c(5.556019, 5.58031, 5.582528, 5.566771, 5.550209)
) %>%
st_as_sf(coords = c("X", "Y"), crs = 4326)
optimized_route <- mb_optimized_route(to_visit,
profile = "driving-traffic"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.