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.
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)list of unnamed elements, each element is either a numeric vector of lat/lon coordinates, or an address string
list of unnamed elements, each element is either a vector of lat/lon coordinates, or an address string
string One of 'driving', 'walking', 'bicycling' or 'transit'.
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()
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.
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
logical If set to true, specifies that the Directions service
may provide more than one route alternative in the response
character vector stating which features should be avoided.
One of 'tolls', 'highways', 'ferries' or 'indoor'
string metric or imperial. Note: Only affects the text displayed
within the distance field. The values are always in metric
string. One of 'best_guess', 'pessimistic' or 'optimistic'.
Only valid with a departure time
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")
vector strings - one of 'less_walking' and
'fewer_transfers'. specifies preferences for transit routes. Only valid for
transit directions.
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
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
string. A valid Google Developers Distance API key
logical. Indicates if the returned JSON should be coerced into a list
a curl proxy object
Either list or JSON string of the distance between origins and destinations
# 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