Learn R Programming

mapsapi (version 0.1.0)

google_matrix: Get distance matrix from the Google Maps Distance Matrix API

Description

Get distance matrix from the Google Maps Distance Matrix API

Usage

google_matrix(origins, destinations, mode = c("driving", "transit", "walking",
  "bicycling"), alternatives = FALSE, key = NULL)

Arguments

origins

Origins, as numeric vector of length two (lon, lat)

destinations

Destinations, as numeric vector of length two (lon, lat)

mode

Travel mode, one of: "driving", "transit", "walking", "bicycling"

alternatives

Whether to return more than one alternative (logical)

key

Google APIs key (optional)

Value

XML document with Google Maps Distance Matrix API response

Examples

Run this code
# NOT RUN {
library(xml2)
doc = as_xml_document(response_matrix)
# }
# NOT RUN {
doc = google_matrix(
  origins = rbind(c(34.81127, 31.89277), c(35.212085, 31.769976)),
  destinations = c(34.781107, 32.085003)
)
locations = c("Haifa", "Tel-Aviv", "Jerusalem", "Beer-Sheva")
doc = google_matrix(
  origins = locations,
  destinations = locations
)
# }

Run the code above in your browser using DataLab