An R package to calculate travel time and distances from ANY coordinate system via Google Maps API.
Returns a data frame with latitude longitude coordinates (wgs84), travel time and distance. This package requires the following R-packages to be installed first: sp, gmapdistance, dplyr. It also requires you to have a Google Maps API key.
Arguments include
If you do not have an API key you can get it here: https://developers.google.com/maps/gmp-get-started
For help you can type in your R console the code below.
?gmapi::traveltime()
Example using UTM32N coordinates
#install.packages(c("sp", "dplyr", "gmapdistance"))
devtools::install_github("kjetilhaukas/gmapi")
# UTM 32N coordinates
x_start <- c(319130,317965,333415,370610,369840,371620)
y_start <- c(6773590,6775225,6785205,6772265,6770175,6770350)
x_end <- c(317105,317120,333645,369670,369910,369905)
y_end <- c(6776765,6776745,6784955,6773200,6774175,6774195)
# Extarct data frame with re-projected coordinates, travel-time, and distance:
gmapi::traveltime(
x_start = x_start,
y_start = y_start,
x_end = x_end,
y_end = y_end,
crs = "+proj=utm +zone=32N +datum=WGS84",
mode = "driving",
key = your_key_goes_here
)
## start_x start_y end_x end_y id time distance status
## 1 5.649018 61.05541 5.608533 61.08293 1 430 4887 OK
## 2 5.625919 61.06953 5.608830 61.08276 2 217 2399 OK
## 3 5.903027 61.16584 5.907515 61.16370 3 154 960 OK
## 4 6.602509 61.06381 6.584471 61.07189 4 173 1412 OK
## 5 6.589681 61.04481 6.588249 61.08072 5 771 9192 OK
## 6 6.622493 61.04697 6.588143 61.08089 6 590 6661 OK
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.