get_route | R Documentation |
This function is a wrapper for the Route Service API. It returns the full route data in a tibble format, or a list of 2 tibbles with results and status information if desired.
get_route( token, start, end, route, date = Sys.Date(), time = format(Sys.time(), format = "%T"), mode = NULL, max_dist = NULL, n_itineraries = 3, status_info = FALSE, decode = 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 |
n_itineraries |
Optional if |
status_info |
Default = |
decode |
Default = |
If no error occurs and status_info = TRUE
:
A list containing information about the query status. If route = "pt"
, the output contains lists request_params
, debug_output
and elevation
. Else, the list contains the variables status
and status_msg
A tibble or sf dataframe containing the data retrieved from the query. This is the only output if status_info = FALSE
. Each row is an itinerary. Output dimensions vary between route = "pt"
and other routes
If an error occurs, the output will be NULL
, along with a warning message.
# returns output tibble ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive") ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "pt", mode = "bus", max_dist = 300, n_itineraries = 2) ## End(Not run) # returns output sf dataframe ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive", decode = TRUE) ## End(Not run) ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "pt", mode = "bus", max_dist = 300, n_itineraries = 2, decode = TRUE) ## End(Not run) # returns list of status list and output tibble ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive", status_info = TRUE) ## End(Not run) # error: output is NULL, warning message shows status code ## Not run: get_route("invalid_token", c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive") # error: output is NULL, warning message shows error message from request ## Not run: get_route(token, c(300, 300), c(400, 500), "cycle") ## Not run: get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "fly")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.