trek: Grab a trek from Google

Description Usage Arguments Value Author(s) See Also Examples

View source: R/trek.R

Description

Grab a trek from Google that will plot over the roadways. 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

1
2
3
4
trek(from, to, mode = c("driving", "walking", "bicycling", "transit"),
  output = c("simple", "all"), alternatives = FALSE, units = "metric",
  messaging = FALSE, urlonly = FALSE, override_limit = FALSE,
  ext = "com", inject = "", ...)

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

output

amount of output

alternatives

should more than one route be provided?

units

"metric"

messaging

turn messaging on/off

urlonly

return only the url?

override_limit

override the current query count (.GoogleRouteQueryCount)

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@gmail.com with the key decoding algorithm due to stackoverflow user akhmed

See Also

https://developers.google.com/maps/documentation/directions/, http://stackoverflow.com/questions/30270011/ggmap-route-finding-doesnt-stay-on-roads, route, routeQueryCheck register_google

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## Not run:  # to cut down on check time

from <- "houston, texas"
to <- "waco, texas"
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"
  )



from <- "rice university houston texas"
to <- "1001 Bissonnet St, Houston, TX 77005"
trek_df <- trek(from, to)
qmplot(lon, lat, data = trek_df, geom = "path", maptype = "terrain",
  color = I("red"), size = I(2), alpha = I(.5)
)

trek_df <- trek(from, to, mode = "walking")
qmplot(lon, lat, data = trek_df, geom = "path", maptype = "terrain",
  color = I("red"), size = I(2), alpha = I(.5)
)

trek_df <- trek(from, to, mode = "transit")
qmplot(lon, lat, data = trek_df, geom = "path", maptype = "terrain",
  color = I("red"), size = I(2), alpha = I(.5)
)


from <- "houston, texas"; to <- "waco, texas"
trek_df <- trek(from, to, alternatives = TRUE)
qmplot(lon, lat, data = trek_df, geom = "path",
  color = route, size = I(2), alpha = I(.5)
)


from <- "los angeles, california"; to <- "new york, new york"
trek_df <- trek(from, to, alternatives = TRUE)
qmplot(lon, lat, data = trek_df, geom = "path",
  color = route, size = I(2), maptype = "terrain",
  zoom = 5
) + facet_wrap(~ route, ncol = 1)





## End(Not run)

fresques/ggmap documentation built on May 28, 2019, 8:40 p.m.