mb_matrix | R Documentation |
Retrieve a matrix of travel times from the Mapbox Directions API
mb_matrix(
origins,
destinations = NULL,
profile = "driving",
fallback_speed = NULL,
output = c("duration", "distance"),
duration_output = c("minutes", "seconds"),
access_token = NULL,
depart_at = NULL,
allow_large_matrix = FALSE
)
origins |
The input coordinates of your request. Acceptable inputs include a list of
coordinate pair vectors in |
destinations |
The destination coordinates of your request. If |
profile |
One of "driving" (the default), "driving-traffic", "walking", or "cycling". |
fallback_speed |
A value expressed in kilometers per hour used to estimate travel time when a route cannot be found between locations. The returned travel time will be based on the straight-line estimate of travel between the locations at the specified fallback speed. |
output |
one of |
duration_output |
one of |
access_token |
A Mapbox access token (required) |
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. |
allow_large_matrix |
|
An R matrix of source-destination travel times.
## Not run:
library(mapboxapi)
library(tigris)
library(mapdeck)
philly_tracts <- tracts("PA", "Philadelphia", cb = TRUE, class = "sf")
downtown_philly <- mb_geocode("Philadelphia City Hall, Philadelphia PA")
time_to_downtown <- mb_matrix(philly_tracts, downtown_philly)
philly_tracts$time <- time_to_downtown
mapdeck(style = mapdeck_style("light")) %>%
add_polygon(
data = philly_tracts,
fill_colour = "time",
fill_opacity = 0.6,
legend = TRUE
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.