# Built-in reponse example
library(xml2)
doc = as_xml_document(response_directions_driving)
r = mp_get_routes(doc)
seg = mp_get_segments(doc)
if (FALSE) {
# Text file with API key
key = readLines("~/key")
# Using 'numeric' input
doc = mp_directions(
origin = c(34.81127, 31.89277),
destination = c(34.781107, 32.085003),
alternatives = TRUE,
key = key
)
# Using 'character' and 'sf' input
library(sf)
doc = mp_directions(
origin = "Beer-Sheva",
destination = c(34.781107, 32.085003) |> st_point() |> st_sfc(crs = 4326),
alternatives = TRUE,
key = key
)
# Comparing traffic models
doc = mp_directions(
origin = "Beer-Sheva",
destination = "Tel Aviv",
departure_time = Sys.time() + as.difftime(1, units = "hours"),
traffic_model = "best_guess",
key = key
)
mp_get_routes(doc)$duration_in_traffic_text
doc = mp_directions(
origin = "Beer-Sheva",
destination = "Tel Aviv",
departure_time = Sys.time() + as.difftime(1, units = "hours"),
traffic_model = "optimistic",
key = key
)
mp_get_routes(doc)$duration_in_traffic_text
doc = mp_directions(
origin = "Beer-Sheva",
destination = "Tel Aviv",
departure_time = Sys.time() + as.difftime(1, units = "hours"),
traffic_model = "pessimistic",
key = key
)
mp_get_routes(doc)$duration_in_traffic_text
}
Run the code above in your browser using DataLab