mp_get_routes: Extract *routes* from Google Maps Directions API response

Description Usage Arguments Value Examples

View source: R/mp_get_routes.R

Description

Extract *routes* from Google Maps Directions API response

Usage

1

Arguments

doc

XML document with Google Maps Directions API response

Value

Line layer (class sf) representing routes

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
library(xml2)

doc = as_xml_document(response_directions_driving)
r = mp_get_routes(doc)
plot(r)

doc = as_xml_document(response_directions_transit)
r = mp_get_routes(doc)
plot(r)

## Not run: 

# Duration in traffic (only with API key)
key = readLines("~/key") # API key
doc = mp_directions(
  origin = c(34.81127, 31.89277),
  destination = c(34.781107, 32.085003),
  departure_time = Sys.time(),
  alternatives = TRUE,
  key = key
)
r = mp_get_routes(doc)
plot(r)

# Using waypoints
doc = mp_directions(
  origin = c(34.81127, 31.89277),
  waypoints = rbind(c(35.01582, 31.90020), c(34.84246, 31.85356)),
  destination = c(34.781107, 32.085003),
  key = key
)
r = mp_get_routes(doc)
plot(r)


## End(Not run)

michaeldorman/mapsapi documentation built on Oct. 4, 2018, 2:30 a.m.