This function takes source and target data, together with options for the API and drawing options, and returns the map with the requested routes.

getTargomoRoutes(
  source_data = NULL,
  source_lat = NULL,
  source_lng = NULL,
  target_data = NULL,
  target_lat = NULL,
  target_lng = NULL,
  source_id = NULL,
  target_id = NULL,
  options = targomoOptions(),
  api_key = Sys.getenv("TARGOMO_API_KEY"),
  region = Sys.getenv("TARGOMO_REGION"),
  config = list(),
  verbose = FALSE,
  progress = FALSE,
  timeout = NULL
)

drawTargomoRoutes(
  map,
  routes,
  drawOptions = routeDrawOptions(),
  group = NULL,
  ...
)

addTargomoRoutes(
  map,
  source_data = NULL,
  source_lat = NULL,
  source_lng = NULL,
  source_id = NULL,
  target_data = NULL,
  target_lat = NULL,
  target_lng = NULL,
  target_id = NULL,
  options = targomoOptions(),
  drawOptions = routeDrawOptions(),
  group = NULL,
  api_key = Sys.getenv("TARGOMO_API_KEY"),
  region = Sys.getenv("TARGOMO_REGION"),
  config = list(),
  verbose = FALSE,
  progress = FALSE,
  timeout = NULL
)

Arguments

source_data, target_data

The source and target points for your routes - supported types are data.frame matrix and objects from the sf and sp packages.

source_lat, source_lng

Columns identifying the latitude and longitude columns in your sourcedata, or numeric vectors of equal length.

target_lat, target_lng

As for source_lat,source_lng but for target data.

source_id, target_id

Formulas or vectors of IDs to give to your source and target points. These will be used to match back to the input data if applicable.

options

A list of targomoOptions to send to the API.

api_key

Your Targomo API key - defaults to the TARGOMO_API_KEY ennvironment variable.

region

Your Targomo region - defaults to the TARGOMO_REGION environment variable.

config

Config options to pass to httr::POST e.g. proxy settings

verbose

Whether to print out information about the API call.

progress

Whether to show a progress bar of the API call.

timeout

Timeout in seconds (leave NULL for no timeout/curl default).

map

A leaflet map

routes

A list of route segments provided by getTargomoRoutes.

drawOptions

A list of routeDrawOptions to determine how to show the resulting routes on the map.

group

The leaflet map group to add the routes to. One group is used for all map elements being drawn per call to the API.

...

Further arguments to pass to addPolylines

Value

For `get*`, a list of objects of class "sf" containing the routes For `draw*` and `add*`, the leaflet map returned with the routes drawn on.

See also

Examples

# \donttest{ # load leaflet package library(leaflet) l <- leaflet() # get route from Big Ben to Tower Bridge r <- getTargomoRoutes(source_lat = 51.5007, source_lng = -0.1246, target_lat = 51.5055, target_lng = -0.0754, options = targomoOptions(travelType = c("bike", "transit")))
#> Multiple (2) travel types supplied - treating each in turn. #> This will make 2 calls to the API.
# draw the routes on the map l %>% drawTargomoRoutes(routes = r) # note, could combine get.. and draw... into one with add... # }