Learn R Programming

mapsapi (version 0.1.0)

google_directions: Get directions from the Google Maps Directions API

Description

Get directions from the Google Maps Directions API

Usage

google_directions(origin, destination, mode = c("driving", "transit",
  "walking", "bicycling"), alternatives = FALSE, avoid = NULL, key = NULL)

Arguments

origin

Origin, as

  • character vector of length one with address to be geocoded

  • numeric vector of length two (lon, lat)

  • matrix with one row and two columns (lon, lat)

  • sf or sfc layer with one feature

destination

Destination, as numeric vector of length two (lon, lat)

mode

Travel mode, one of: "driving" (default), "transit", "walking", "bicycling"

alternatives

Whether to return more than one alternative (logical)

avoid

NULL (default) or one of: "tolls", "highways", "ferries"

key

Google APIs key (optional)

Value

XML document with Google Maps Directions API response

Examples

Run this code
# NOT RUN {
library(xml2)
doc = as_xml_document(response_directions)
# }
# NOT RUN {
doc = google_directions(
  origin = c(34.81127, 31.89277),
  destination = c(34.781107, 32.085003),
  alternatives = TRUE
)
doc = google_directions(
  origin = "Beer-Sheva",
  destination = c(34.781107, 32.085003) %>% st_point %>% st_sfc(crs = 4326),
  alternatives = TRUE
)
# }

Run the code above in your browser using DataLab