# 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)
# }
Run the code above in your browser using DataLab