Learn R Programming

googleway (version 2.0.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,
  waypoints = NULL, alternatives = FALSE, avoid = NULL,
  units = c("metric", "imperial"), traffic_model = NULL,
  transit_mode = NULL, transit_routing_preference = NULL, language = NULL,
  region = 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.

waypoints

list of waypoints, expressed as either a vector of lat/lon coordinates, or a string address to be geocoded. Only available for transit, walking or bicycling modes. List elements must be named either 'stop' or 'via', where 'stop' is used to indicate a stopover for a waypoint, and 'via' will not stop at the waypoint. See https://developers.google.com/maps/documentation/directions/intro#Waypoints for details

alternatives

logical If set to true, specifies that the Directions service may provide more than one route alternative in the response

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

region

string. Specifies the region code, specified as a ccTLD ("top-level domain"). See region basing for details https://developers.google.com/maps/documentation/directions/intro#RegionBiasing

key

string. A valid Google Developers Distance API key

simplify

logical. Indicates if the returned JSON should be coerced into a list

curl_proxy

a curl proxy object

Value

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

Examples

Run this code
# NOT RUN {
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