google_directions {googleway} | R Documentation |
Google Directions
Description
The Google Maps Directions API is a service that calculates directions between locations. You can search for directions for several modes of transportation, including transit, driving, walking, or cycling.
Usage
google_directions(
origin,
destination,
mode = c("driving", "walking", "bicycling", "transit"),
departure_time = NULL,
arrival_time = NULL,
waypoints = NULL,
optimise_waypoints = FALSE,
alternatives = FALSE,
avoid = NULL,
units = c("metric", "imperial"),
traffic_model = NULL,
transit_mode = NULL,
transit_routing_preference = NULL,
language = NULL,
region = NULL,
key = get_api_key("directions"),
simplify = TRUE,
curl_proxy = NULL
)
Arguments
origin |
Origin location as either a one or two column data.frame, a list of unnamed elements, each element is either a numeric vector of lat/lon coordinates, an address string or a place_id, or a vector of a pair of lat / lon coordinates |
destination |
destination location as either a one or two column data.frame, a list of unnamed elements, each element is either a numeric vector of lat/lon coordinates, an address string or place_id, or a vector of a pair of lat / lon coordinates |
mode |
|
departure_time |
The desired time of departure.
Use either a |
arrival_time |
Specifies the desired time of arrival for transit requests.
Use either a |
waypoints |
list of waypoints, expressed as either |
optimise_waypoints |
|
alternatives |
|
avoid |
|
units |
|
traffic_model |
|
transit_mode |
|
transit_routing_preference |
|
language |
|
region |
|
key |
|
simplify |
|
curl_proxy |
a curl proxy object |
Value
Either list or JSON string of the route between origin and destination
API use and limits
The amount of queries you can make to Google's APIs is dependent on both the service and the API you are using.
Each API has specific quotas and limits. Check Google's API documentation for details.
View your usage at the Google Cloud Console https://console.cloud.google.com/
Each API can only accept and return one request at a time. If you write a loop to make multiple API calls you should ensure you don't go over your quota / limits during the loop.
Examples
## Not run:
set_key("YOUR_GOOGLE_API_KEY")
## using lat/long coordinates
google_directions(origin = c(-37.8179746, 144.9668636),
destination = c(-37.81659, 144.9841),
mode = "walking")
## using address string
google_directions(origin = "Flinders Street Station, Melbourne",
destination = "MCG, Melbourne",
mode = "walking")
google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
waypoints = list(stop = c(-37.81659, 144.9841),
via = "Ringwood, Victoria"),
mode = "driving",
alternatives = FALSE,
avoid = c("TOLLS", "highways"),
units = "imperial",
simplify = TRUE)
## using 'now' as departure time
google_directions(origin = "Flinders Street Station, Melbourne",
destination = "MCG, Melbourne",
departure_time = 'now')
## waypoints expressed as an encoded polyline
polyWaypoints <- encode_pl(tram_stops[1:2, c("stop_lat")], tram_stops[1:2, c("stop_lon")])
polyWaypoints <- list(via = paste0("enc:", polyWaypoints, ":"))
google_directions(origin = "Melbourne Zoo, Melbourne",
destination = "Studley Park, Melbourne",
waypoints = polyWaypoints)
## using bus and less walking
res <- google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
departure_time = Sys.time() + (24 * 60 * 60),
mode = "transit",
transit_mode = "bus",
transit_routing_preference = "less_walking",
simplify = FALSE)
## using arrival time
res <- google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
arrival_time = Sys.time() + (24 * 60 * 60),
mode = "transit",
transit_mode = "bus",
transit_routing_preference = "less_walking",
simplify = FALSE)
## return results in French
res <- google_directions(origin = "Melbourne Airport, Australia",
destination = "Portsea, Melbourne, Australia",
arrival_time = Sys.time() + (24 * 60 * 60),
mode = "transit",
transit_mode = "bus",
transit_routing_preference = "less_walking",
language = "fr",
simplify = FALSE)
## End(Not run)