Learn R Programming

googleway (version 2.2.0)

google_distance: Google Distance

Description

The Google Maps Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

Usage

google_distance(origins, destinations, mode = c("driving", "walking",
  "bicycling", "transit"), departure_time = NULL, arrival_time = NULL,
  avoid = NULL, units = c("metric", "imperial"), traffic_model = NULL,
  transit_mode = NULL, transit_routing_preference = NULL, language = NULL,
  key, simplify = TRUE, curl_proxy = NULL)

Arguments

origins

list of unnamed elements, each element is either a numeric vector of lat/lon coordinates, or an address string

destinations

list of unnamed elements, each element is either a vector of lat/lon coordinates, or an address string

mode

string One of 'driving', 'walking', 'bicycling' or 'transit'.

departure_time

POSIXct. Specifies the desired time of departure. Must be in the future (i.e. greater than sys.time()). If no value is specified it defaults to Sys.time()

arrival_time

POSIXct. Specifies teh desired time of arrival. Note you can only specify one of arrival_time or departure_time, not both. If both are supplied, departure_time will be used.

avoid

character vector stating which features should be avoided. One of 'tolls', 'highways', 'ferries' or 'indoor'

units

string metric or imperial. Note: Only affects the text displayed within the distance field. The values are always in metric

traffic_model

string. One of 'best_guess', 'pessimistic' or 'optimistic'. Only valid with a departure time

transit_mode

vector of strings, either 'bus', 'subway', 'train', 'tram' or 'rail'. Only vaid where mode = 'transit'. Note that 'rail' is equivalent to transit_mode=c("train", "tram", "subway")

transit_routing_preference

vector strings - one of 'less_walking' and 'fewer_transfers'. specifies preferences for transit routes. Only valid for transit directions.

language

string. Specifies the language in which to return the results. See the list of supported languages: https://developers.google.com/maps/faq#using-google-maps-apis If no langauge is supplied, the service will attempt to use the language of the domain from which the request was sent

key

string. A valid Google Developers Distance API key

simplify

logical - TRUE indicates the returned JSON will be coerced into a list. FALSE indicates the returend JSON will be returned as a string

curl_proxy

a curl proxy object

Value

Either list or JSON string of the distance between origins and destinations

Examples

Run this code

google_distance(origins = list(c("Melbourne Airport, Australia"),
                             c("MCG, Melbourne, Australia"),
                             c(-37.81659, 144.9841)),
                             destinations = c("Portsea, Melbourne, Australia"),
                             key = "<your valid api key>",
                             simplify = FALSE)




Run the code above in your browser using DataLab