Learn R Programming

ggmap (version 2.6.1)

route: Grab a route from Google

Description

Grab a route from Google. Note that in most cases by using this function you are agreeing to the Google Maps API Terms of Service at https://developers.google.com/maps/terms.

Usage

route(from, to, mode = c("driving", "walking", "bicycling", "transit"),
  structure = c("legs", "route"), output = c("simple", "all"),
  alternatives = FALSE, messaging = FALSE, sensor = FALSE,
  override_limit = FALSE)

Arguments

from

name of origin addresses in a data frame (vector accepted)

to

name of destination addresses in a data frame (vector accepted)

mode

driving, bicycling, walking, or transit

structure

structure of output, see examples

output

amount of output

alternatives

should more than one route be provided?

messaging

turn messaging on/off

sensor

whether or not the geocoding request comes from a device with a location sensor

override_limit

override the current query count (.GoogleRouteQueryCount)

Value

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

See Also

https://developers.google.com/maps/documentation/directions/, legs2route, routeQueryCheck, geom_leg

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
 # to cut down on check time

from <- "houson, texas"
to <- "waco, texas"
route_df <- route(from, to, structure = "route")
qmap("college station, texas", zoom = 8) +
  geom_path(
    aes(x = lon, y = lat),  colour = "red", size = 1.5,
    data = route_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"
  )

routeQueryCheck()




# }
# NOT RUN {
# }

Run the code above in your browser using DataLab