View source: R/get_summ_route.R
get_summ_route | R Documentation |
This function is a wrapper for the Route Service API. However, it only returns the total time, distance and optionally the route geometry between two points.
If route = "pt"
, only the best route is chosen (i.e. n_itineraries = 1
).
get_summ_route(
token,
start,
end,
route,
date = format(Sys.Date(), "%m-%d-%Y"),
time = format(Sys.time(), "%T"),
mode = NULL,
max_dist = NULL,
route_geom = FALSE
)
token |
User's API token. This can be retrieved using |
start |
Vector of c(lat, lon) coordinates for the route start point |
end |
Vector of c(lat, lon) coordinates for the route end point |
route |
Type of route. Accepted values are |
date |
Default = current date. Date for which route is requested. |
time |
Default = current time. Time for which route is requested. |
mode |
Required if |
max_dist |
Optional if |
route_geom |
Default = FALSE. Whether to return decoded route_geometry. Please ensure packages googlePolylines and sf are installed and note that this is a lossy conversion. |
If no error occurs, a tibble of 1 x 2 with the variables:
The total time taken for this route
The total distance travelled for this route
If an error occurs, the output will be NA
, along with a warning message.
# returns output tibble
## Not run: get_summ_route(token, c(1.320981, 103.844150), c(1.326762, 103.8559), "drive")
## Not run: get_summ_route(token, c(1.320981, 103.844150), c(1.326762, 103.8559), "pt",
mode = "bus", max_dist = 300)
## End(Not run)
# returns output sf dataframe
## Not run: get_summ_route(token, c(1.320981, 103.844150), c(1.326762, 103.8559),
"drive", route_geom = TRUE)
## End(Not run)
## Not run: get_summ_route(token, c(1.320981, 103.844150), c(1.326762, 103.8559), "pt",
mode = "bus", max_dist = 300, route_geom = TRUE)
## End(Not run)
#'
# error: output is NULL, warning message shows status code
## Not run: get_summ_route("invalid_token", c(1.320981, 103.844150), c(1.326762, 103.8559), "drive")
# error: output is NULL, warning message shows error message from request
## Not run: get_summ_route(token, c(300, 300), c(400, 500), "cycle")
## Not run: get_summ_route(token, c(1.320981, 103.844150), c(1.326762, 103.8559), "fly")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.