TravelTime Docs logo
TravelTime API
Overview
Developer Tools
Database Plugins
TravelTime API
SDK
TravelTime API
Isochrone API
JSON
Travel Time Matrix API
JSON
Travel Time Matrix API
Protocol Buffers
Routes API
Geocoding API
Additional API Reference
Error Handling
TravelTime API
ArcGIS plugin
QGIS plugin
Alteryx plugin

traveltimeR: Travel Time R SDKanchor icon

traveltimeR is a R SDK for Travel Time API (https://traveltime.com/). Travel Time API helps users find locations by journey time rather than using ‘as the crow flies’ distance. Time-based searching gives users more opportunities for personalisation and delivers a more relevant search.

Installationanchor icon

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("traveltime-dev/traveltime-sdk-r")

System requirementsanchor icon

traveltimeR uses rprotobuf as a dependency. If your package installation fails, please make sure you have the system requirements covered for rprotobuf

Debian/Ubuntuanchor icon

sudo apt-get install protobuf-compiler libprotobuf-dev libprotoc-dev

MacOSanchor icon

brew install protobuf

There also exists similar commands on other distributions or operating systems.

Authenticationanchor icon

In order to authenticate with Travel Time API, you will have to supply the Application Id and Api Key.

library(traveltimeR)

#store your credentials in an environment variable
Sys.setenv(TRAVELTIME_ID = "YOUR_API_ID")
Sys.setenv(TRAVELTIME_KEY = "YOUR_API_KEY")

Usageanchor icon

Given origin coordinates, find shapes of zones reachable within corresponding travel time. Find unions/intersections between different searches

Function accepts object that matches API json spec.

departure_search <-
make_search(id = "public transport from Trafalgar Square",
            departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 900,
            coords = list(lat = 51.507609, lng = -0.128315),
            transportation = list(type = "public_transport"),
            properties = list('is_only_walking'))

result <- time_map(departure_searches = departure_search)

Given origin and destination points filter out points that cannot be reached within specified time limit. Find out travel times, distances and costs between an origin and up to 2,000 destination points.

Function accepts object that matches API json spec.

locationsDF <- data.frame(
  id = c('London center', 'Hyde Park', 'ZSL London Zoo'),
  lat = c(51.508930, 51.508824, 51.536067),
  lng = c(-0.131387, -0.167093, -0.153596)
)
locations <- apply(locationsDF, 1, function(x)
  make_location(id = x['id'], coords = list(lat = as.numeric(x["lat"]),
                                            lng = as.numeric(x["lng"]))))
locations <- unlist(locations, recursive = F)

departure_search <-
  make_search(id = "departure search example",
              departure_location_id = "London center",
              arrival_location_ids = list("Hyde Park", "ZSL London Zoo"),
              departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
              travel_time = 1800,
              properties = list('travel_time'),
              transportation = list(type = "bus"),
              range = list(enabled = T, width = 600, max_results = 3))

arrival_search <-
  make_search(id = "arrival search example",
              arrival_location_id = "London center",
              departure_location_ids = list("Hyde Park", "ZSL London Zoo"),
              arrival_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
              travel_time = 1800,
              properties = list('travel_time', "distance", "distance_breakdown", "fares"),
              transportation = list(type = "public_transport"),
              range = list(enabled = T, width = 600, max_results = 3))

result <-
  time_filter(
    departure_searches = departure_search,
    arrival_searches = arrival_search,
    locations = locations
  )

print(result)

Returns routing information between source and destinations.

Function accepts object that matches API json spec.

locations <- c(
  make_location(
    id = 'London center',
    coords = list(lat = 51.508930, lng = -0.131387)),
  make_location(
    id = 'Hyde Park',
    coords = list(lat = 51.508824, lng = -0.167093)),
  make_location(
    id = 'ZSL London Zoo',
    coords = list(lat = 51.536067, lng = -0.153596))
)

departure_search <-
  make_search(id = "departure search example",
              departure_location_id = "London center",
              arrival_location_ids = list("Hyde Park", "ZSL London Zoo"),
              departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
              properties = list("travel_time", "distance", "route"),
              transportation = list(type = "driving"))

arrival_search <-
  make_search(id = "arrival  search example",
              arrival_location_id = "London center",
              departure_location_ids = list("Hyde Park", "ZSL London Zoo"),
              arrival_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
              properties = list('travel_time', "distance", "route", "fares"),
              transportation = list(type = "public_transport"),
              range = list(enabled = T, width = 1800, max_results = 1))

result <-
  routes(
    departure_searches = departure_search,
    arrival_searches = arrival_search,
    locations = locations
  )

print(result)

A very fast version of time_filter(). However, the request parameters are much more limited. Currently only supports UK and Ireland.

Function accepts object that matches API json spec.

locations <-
c(
  make_location('London center', list(lat = 51.508930, lng = -0.131387)),
  make_location('Hyde Park', list(lat = 51.508824, lng = -0.167093)),
  make_location('ZSL London Zoo', list(lat = 51.536067, lng = -0.153596))
)

arrival_many_to_one <- 
make_search(id = "arrive-at many-to-one search example",
            arrival_location_id = "London center",
            departure_location_ids = list("Hyde Park", "ZSL London Zoo"),
            travel_time = 1900,
            arrival_time_period = "weekday_morning",
            properties = list('travel_time', "fares"),
            transportation = list(type = "public_transport"))


arrival_one_to_many <- 
make_search(id = "arrive-at one-to-many search example",
            departure_location_id = "London center",
            arrival_location_ids = list("Hyde Park", "ZSL London Zoo"),
            travel_time = 1900,
            properties = list('travel_time', "fares"),
            arrival_time_period = "weekday_morning",
            transportation = list(type = "public_transport"))

result <- time_filter_fast(locations, arrival_many_to_one, arrival_one_to_many)

print(result)

The Travel Time Matrix (Fast) endpoint is available with even higher performance through a version using Protocol Buffers (Protobuf). This version of the API is built to create large travel time matrices with extremely low response times

result <- time_filter_fast_proto(
  departureLat = 51.508930,
  departureLng = -0.131387,
  destinationCoordinates = data.frame(
    lat = c(51.508824),
    lng = c(-0.167093)
  ),
  transportation = 'driving+ferry',
  travelTime = 7200,
  country = "uk"
)

print(result)

Find districts that have a certain coverage from origin (or to destination) and get statistics about postcodes within such districts. Currently only supports United Kingdom.

Function accepts object that matches API json spec.

departure_search <-
make_search(id = "public transport from Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            reachable_postcodes_threshold = 0.1,
            properties = list("coverage", "travel_time_reachable", "travel_time_all"))

arrival_search <-
make_search(id = "public transport to Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            arrival_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            reachable_postcodes_threshold = 0.1,
            properties = list("coverage", "travel_time_reachable", "travel_time_all"))

result <-
time_filter_postcode_districts(
  departure_searches = departure_search,
  arrival_searches = arrival_search
)

print(result)

Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors. Currently only supports United Kingdom.

Function accepts object that matches API json spec.

departure_search <-
make_search(id = "public transport from Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            reachable_postcodes_threshold = 0.1,
            properties = list("coverage", "travel_time_reachable", "travel_time_all"))

arrival_search <-
make_search(id = "public transport to Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            arrival_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            reachable_postcodes_threshold = 0.1,
            properties = list("coverage", "travel_time_reachable", "travel_time_all"))

result <-
time_filter_postcode_sectors(
  departure_searches = departure_search,
  arrival_searches = arrival_search
)

print(result)

Find reachable postcodes from origin (or to destination) and get statistics about such postcodes. Currently only supports United Kingdom.

Function accepts object that matches API json spec.

departure_search <-
make_search(id = "public transport from Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            departure_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            properties = list('travel_time', 'distance'))

arrival_search <-
make_search(id = "public transport to Trafalgar Square",
            coords = list(lat = 51.507609, lng = -0.128315),
            arrival_time = strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ"),
            travel_time = 1800,
            transportation = list(type = "public_transport"),
            properties = list('travel_time', 'distance'))

result <-
time_filter_postcodes(
  departure_searches = departure_search,
  arrival_searches = arrival_search
)

print(result)

Match a query string to geographic coordinates.

Function accepts object that might has these properties:

geocoding('Parliament square')

Attempt to match a latitude, longitude pair to an address.

Function accepts object that might has these properties:

geocoding_reverse(lat=51.507281, lng=-0.132120)

Get information about currently supported countries.

map_info()

Find out what points are supported by the api.

Function accepts object that matches API json spec.

locationsDF <- data.frame(
  id = c('Kaunas', 'London', 'Bangkok', 'Lisbon'),
  lat = c(54.900008, 51.506756, 13.761866, 38.721869),
  lng = c(23.957734, -0.128050, 100.544818, -9.138549)
)
locations <- apply(locationsDF, 1, function(x)
  make_location(id = x['id'], coords = list(lat = as.numeric(x["lat"]),
                                            lng = as.numeric(x["lng"]))))
supported_locations(unlist(locations, recursive = F))