route: Grab a route from Google

routeR Documentation

Grab a route from Google

Description

Route two locations: determine a sequence of steps (legs) between two locations using the Google Directions API. Note: To use Google's Directions API, you must first enable the API in the Google Cloud Platform Console. See register_google().

Usage

route(
  from,
  to,
  mode = c("driving", "walking", "bicycling", "transit"),
  structure = c("legs", "route"),
  output = c("simple", "all"),
  alternatives = FALSE,
  units = "metric",
  urlonly = FALSE,
  override_limit = FALSE,
  ext = "com",
  inject = "",
  ...
)

routeQueryCheck()

Arguments

from

vector of origin addresses

to

vector of destination addresses

mode

driving, bicycling, walking, or transit

structure

structure of output, "legs" or "route", see examples

output

amount of output ("simple" or "all")

alternatives

should more than one route be provided?

units

"metric"

urlonly

return only the url?

override_limit

override the current query count

ext

domain extension (e.g. "com", "co.nz")

inject

character string to add to the url

...

...

Value

a data frame (output="simple") or all of the geocoded information (output="all")

Author(s)

David Kahle david@kahle.io

See Also

https://developers.google.com/maps/documentation/directions/, trek(), legs2route(), geom_leg(), register_google()

Examples


## Not run:  requires Google API key, see ?register_google

## basic usage
########################################

from <- "houston, texas"
to <- "waco, texas"

route(from, to, structure = "legs")
route(from, to, structure = "route")

route(from, to, alternatives = TRUE)


## comparison to trek
########################################
(route_df <- route(from, to, structure = "route"))
(trek_df  <-  trek(from, to, structure = "route"))

qmap("college station, texas", zoom = 8) +
  geom_path(
    aes(x = lon, y = lat),  colour = "red",
    size = 1.5, alpha = .5,
    data = route_df, lineend = "round"
  ) +
  geom_path(
    aes(x = lon, y = lat),  colour = "blue",
    size = 1.5, alpha = .5,
    data = trek_df, lineend = "round"
  )

qmap("college station, texas", zoom = 6) +
  geom_path(
    aes(x = lon, y = lat), colour = "red", size = 1.5,
    data = route_df, lineend = "round"
  )






## End(Not run)


dkahle/ggmap documentation built on March 3, 2024, 8:19 a.m.