mp_directions: Get directions from the Google Maps Directions API

Description Usage Arguments Value Note References Examples

View source: R/mp_directions.R

Description

Get directions from the Google Maps Directions API

Usage

1
2
3
4
mp_directions(origin, waypoints = NULL, destination,
  mode = c("driving", "transit", "walking", "bicycling"),
  arrival_time = NULL, departure_time = NULL, alternatives = FALSE,
  avoid = NULL, region = 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 point layer with one feature

waypoints

Waypoints, in one of the same formats as for origins but possibly with more than one location, i.e.

  • character vector with addresses to be geocoded

  • numeric vector of length two (lon, lat)

  • matrix with two columns (lon, lat)

  • sf or sfc point layer

destination

Destination, in one of the same formats as for origins

mode

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

arrival_time

The desired time of arrival for transit directions, as POSIXct

departure_time

The desired time of departure, as POSIXct

alternatives

Whether to return more than one alternative (logical)

avoid

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

region

The region code, specified as a ccTLD ("top-level domain") two-character value (e.g. "es" for Spain) (optional)

key

Google APIs key (optional)

Value

XML document with Google Maps Directions API response

Note

References

https://developers.google.com/maps/documentation/directions/intro

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
# Built-in reponse example
library(xml2)
doc = as_xml_document(response_directions_driving)
r = mp_get_routes(doc)
seg = mp_get_segments(doc)

## Not run: 

# Using 'numeric' input
doc = mp_directions(
  origin = c(34.81127, 31.89277),
  destination = c(34.781107, 32.085003),
  alternatives = TRUE
)

# Using 'character' and 'sf' input
library(magrittr); library(sf)
doc = mp_directions(
  origin = "Beer-Sheva",
  destination = c(34.781107, 32.085003) %>% st_point %>% st_sfc(crs = 4326),
  alternatives = TRUE
)

## End(Not run)

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