hmac
sha1 algorithm.
For smaller batch requests, it is also possible to access Google's "standard API"
with this function (see this page to obtain a free API key).
drive_time(address, dest, auth = "standard_api", privkey = NULL, clientid = NULL, clean = "TRUE", travel_mode = "driving", units = "metric", verbose = FALSE, add_date = "none", language = "en-EN", messages = FALSE, small = FALSE)
address_cleaner
function.
This vector becomes the starting point of the distance calculation.
If the length of this parameter is 1 and destination's length is greater than 1, address is replicated to match the length of destination
(e.g., when you are calculating distances between one specific location and two or more destinations).
Note: addresses should be in raw form, not URL encoded (e.g., of the form: 123 Main Street, Somewhere, NY 12345 USA)(country is optional but recommended).address_cleaner
function.TRUE
, applies address_cleaner
to the address and destination vectors.TRUE
, displays additional progress output.TRUE
, displays warning and error messages generated by the API calls within the pull_geo_data
function (e.g. connection errors, malformed signatures, etc.)TRUE
, only distance (as per units
), travel time (in hours), and (optionally, via add_date
) the calendar date are returned.TRUE
) with the following parameters stored from the response object:
address
and dest
in miles or kilometers, as per the units
parameter.
address
and dest
.
address
and dest
return_stat
are
placement
package, and suggests a connection error orcurred
while fetch the url(s) (e.g. due to intermittent internet connectivity, problems reaching the Google maps API, etc.).
# Bike from the NYC to Google!
address <- c("350 5th Ave, New York, NY 10118, USA",
"1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA")
coordset <- geocode_url(address, auth="standard_api", privkey="",
clean=TRUE, add_date='today', verbose=TRUE)
# Save coordinates. Google requires a format of: "lat,lng" (with no spaces)
start <- paste(coordset$lat[1],coordset$lng[1], sep=",")
end <- paste(coordset$lat[2],coordset$lng[2], sep=",")
# Get the travel time by bike (a mere 264 hours!) and distance in miles:
howfar_miles <- drive_time(address=start, dest=end, auth="standard_api",
privkey="", clean=FALSE, add_date='today',
verbose=FALSE, travel_mode="bicycling",
units="imperial")
# Get the distance in kilometers using physical addresses instead of lat/lng:
howfar_kms <- drive_time(
address="350 5th Ave, New York, NY 10118, USA",
dest="1600 Amphitheatre Pkwy, Mountain View, CA 94043",
auth="standard_api", privkey="", clean=FALSE,
add_date='today', verbose=FALSE, travel_mode="bicycling",
units="imperial"
)
with(howfar_kms, cat("Cycling from NYC to ", destination,
":\n", dist_txt, "\n", time_txt, sep=""))
Run the code above in your browser using DataLab