Get directions for different modes of transport.

ors_directions(
  coordinates,
  profile = ors_profile(),
  format = c("geojson", "json", "gpx"),
  ...,
  api_key = ors_api_key(),
  output = c("parsed", "text", "sf")
)

Arguments

coordinates

List of longitude, latitude coordinate pairs visited in order, alternatively a two column matrix or data.frame.

profile

Route profile, defaults to "driving-car".

format

Response format, defaults to "geojson"

...

Optional parameters as described here

api_key

Character scalar containing openrouteservice API key

output

Output format. By default the response is being parsed to a list-based R object

Value

Route between two or more locations in the selected format structured according to output:

  • for "text", a character vector of length 1 re-encoded to UTF-8.

  • for "parsed", a parsed R object.

  • for "sf", a simple features sf object.

Author

Andrzej Oleś andrzej@openrouteservice.org

Examples

coordinates = list(c(8.34234, 48.23424), c(8.34423, 48.26424))

# simple call
ors_directions(coordinates, preference="fastest")
#> <ors_directions>
#> List of 4
#>  $ type    : chr "FeatureCollection"
#>  $ metadata:List of 6
#>   ..$ attribution   : chr "openrouteservice.org | OpenStreetMap contributors"
#>   ..$ service       : chr "routing"
#>   ..$ timestamp     : num 1.7e+12
#>   ..$ query         :List of 4
#>   .. ..$ coordinates: num [1:2, 1:2] 8.34 8.34 48.23 48.26
#>   .. ..$ profile    : chr "driving-car"
#>   .. ..$ preference : chr "fastest"
#>   .. ..$ format     : chr "geojson"
#>   ..$ engine        :List of 3
#>   .. ..$ version   : chr "7.1.0"
#>   .. ..$ build_date: chr "2023-07-09T01:31:50Z"
#>   .. ..$ graph_date: chr "2023-09-17T10:17:18Z"
#>   ..$ system_message: chr "Preference 'fastest' has been deprecated, using 'recommended'."
#>  $ bbox    : num [1:4] 8.33 48.23 8.35 48.26
#>  $ features:List of 1
#>   ..$ :List of 4
#>   .. ..$ bbox      : num [1:4] 8.33 48.23 8.35 48.26
#>   .. ..$ type      : chr "Feature"
#>   .. ..$ properties:List of 5
#>   .. .. ..$ transfers : int 0
#>   .. .. ..$ fare      : int 0
#>   .. .. ..$ segments  :List of 1
#>   .. .. .. ..$ :List of 3
#>   .. .. .. .. ..$ distance: num 5477
#>   .. .. .. .. ..$ duration: num 804
#>   .. .. .. .. ..$ steps   :List of 16
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 247
#>   .. .. .. .. .. .. ..$ duration   : num 59.3
#>   .. .. .. .. .. .. ..$ type       : int 11
#>   .. .. .. .. .. .. ..$ instruction: chr "Head south on Benatweg"
#>   .. .. .. .. .. .. ..$ name       : chr "Benatweg"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 0 8
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 51.8
#>   .. .. .. .. .. .. ..$ duration   : num 12.4
#>   .. .. .. .. .. .. ..$ type       : int 6
#>   .. .. .. .. .. .. ..$ instruction: chr "Continue straight onto Benatweg"
#>   .. .. .. .. .. .. ..$ name       : chr "Benatweg"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 8 10
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 1684
#>   .. .. .. .. .. .. ..$ duration   : num 135
#>   .. .. .. .. .. .. ..$ type       : int 1
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn right onto Hölzle, K 5528"
#>   .. .. .. .. .. .. ..$ name       : chr "Hölzle, K 5528"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 10 64
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 264
#>   .. .. .. .. .. .. ..$ duration   : num 31.6
#>   .. .. .. .. .. .. ..$ type       : int 1
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn right"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 64 73
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 302
#>   .. .. .. .. .. .. ..$ duration   : num 36.2
#>   .. .. .. .. .. .. ..$ type       : int 0
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn left"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 73 85
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 536
#>   .. .. .. .. .. .. ..$ duration   : num 64.3
#>   .. .. .. .. .. .. ..$ type       : int 0
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn left"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 85 96
#>   .. .. .. .. .. .. [list output truncated]
#>   .. .. ..$ way_points: int [1:2] 0 165
#>   .. .. ..$ summary   :List of 2
#>   .. .. .. ..$ distance: num 5477
#>   .. .. .. ..$ duration: num 804
#>   .. ..$ geometry  :List of 2
#>   .. .. ..$ coordinates: num [1:166, 1:2] 8.34 8.34 8.34 8.34 8.34 ...
#>   .. .. ..$ type       : chr "LineString"

# customized options
ors_directions(coordinates, profile="cycling-mountain", elevation=TRUE)
#> <ors_directions>
#> List of 4
#>  $ type    : chr "FeatureCollection"
#>  $ metadata:List of 5
#>   ..$ attribution: chr "openrouteservice.org | OpenStreetMap contributors"
#>   ..$ service    : chr "routing"
#>   ..$ timestamp  : num 1.7e+12
#>   ..$ query      :List of 4
#>   .. ..$ coordinates: num [1:2, 1:2] 8.34 8.34 48.23 48.26
#>   .. ..$ profile    : chr "cycling-mountain"
#>   .. ..$ format     : chr "geojson"
#>   .. ..$ elevation  : logi TRUE
#>   ..$ engine     :List of 3
#>   .. ..$ version   : chr "7.1.0"
#>   .. ..$ build_date: chr "2023-06-27T12:02:26Z"
#>   .. ..$ graph_date: chr "2023-09-05T04:12:35Z"
#>  $ bbox    : num [1:6] 8.33 48.23 659.9 8.35 48.26 ...
#>  $ features:List of 1
#>   ..$ :List of 4
#>   .. ..$ bbox      : num [1:6] 8.33 48.23 659.9 8.35 48.26 ...
#>   .. ..$ type      : chr "Feature"
#>   .. ..$ properties:List of 7
#>   .. .. ..$ ascent    : num 120
#>   .. .. ..$ descent   : num 134
#>   .. .. ..$ transfers : int 0
#>   .. .. ..$ fare      : int 0
#>   .. .. ..$ segments  :List of 1
#>   .. .. .. ..$ :List of 5
#>   .. .. .. .. ..$ distance: num 5206
#>   .. .. .. .. ..$ duration: num 1272
#>   .. .. .. .. ..$ steps   :List of 15
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 889
#>   .. .. .. .. .. .. ..$ duration   : num 321
#>   .. .. .. .. .. .. ..$ type       : int 11
#>   .. .. .. .. .. .. ..$ instruction: chr "Head southwest"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 0 24
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 823
#>   .. .. .. .. .. .. ..$ duration   : num 165
#>   .. .. .. .. .. .. ..$ type       : int 5
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn slight right onto Sulzbacher Straße, K 5528"
#>   .. .. .. .. .. .. ..$ name       : chr "Sulzbacher Straße, K 5528"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 24 52
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 264
#>   .. .. .. .. .. .. ..$ duration   : num 59.3
#>   .. .. .. .. .. .. ..$ type       : int 1
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn right"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 52 61
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 302
#>   .. .. .. .. .. .. ..$ duration   : num 67.9
#>   .. .. .. .. .. .. ..$ type       : int 0
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn left"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 61 73
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 536
#>   .. .. .. .. .. .. ..$ duration   : num 118
#>   .. .. .. .. .. .. ..$ type       : int 0
#>   .. .. .. .. .. .. ..$ instruction: chr "Turn left"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 73 84
#>   .. .. .. .. .. ..$ :List of 6
#>   .. .. .. .. .. .. ..$ distance   : num 248
#>   .. .. .. .. .. .. ..$ duration   : num 55.8
#>   .. .. .. .. .. .. ..$ type       : int 13
#>   .. .. .. .. .. .. ..$ instruction: chr "Keep right"
#>   .. .. .. .. .. .. ..$ name       : chr "-"
#>   .. .. .. .. .. .. ..$ way_points : int [1:2] 84 92
#>   .. .. .. .. .. .. [list output truncated]
#>   .. .. .. .. ..$ ascent  : num 120
#>   .. .. .. .. ..$ descent : num 134
#>   .. .. ..$ way_points: int [1:2] 0 153
#>   .. .. .. [list output truncated]
#>   .. ..$ geometry  :List of 2
#>   .. .. ..$ coordinates: num [1:154, 1:3] 8.34 8.34 8.34 8.34 8.34 ...
#>   .. .. ..$ type       : chr "LineString"

# list of locations as `data.frame` output as simple features `sf` object
locations <- data.frame(lng = c(8.34234, 8.327807, 8.34423),
                        lat = c(48.23424, 48.239368, 48.26424))
ors_directions(locations, output = "sf")
#>   transfers
#> 1         0
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             geometry
#> 1 8.344268, 8.344147, 8.343946, 8.343854, 8.343320, 8.343098, 8.342861, 8.342712, 8.342328, 8.341843, 8.341711, 8.340515, 8.340359, 8.339942, 8.339417, 8.339260, 8.339220, 8.339223, 8.339411, 8.339409, 8.339355, 8.339251, 8.338979, 8.338824, 8.338489, 8.338386, 8.338316, 8.338226, 8.338175, 8.338114, 8.337902, 8.337249, 8.337061, 8.336708, 8.336131, 8.335783, 8.335414, 8.335074, 8.334962, 8.334932, 8.334891, 8.334806, 8.334515, 8.334384, 8.334146, 8.334041, 8.333953, 8.333861, 8.333611, 8.333482, 8.333392, 8.333340, 8.333317, 8.333328, 8.333436, 8.333446, 8.333404, 8.333292, 8.333145, 8.332979, 8.332862, 8.332688, 8.332346, 8.332214, 8.331826, 8.331389, 8.330941, 8.330020, 8.329920, 8.329540, 8.328893, 8.328703, 8.328396, 8.328169, 8.328164, 8.327920, 8.327493, 8.327338, 8.327158, 8.326912, 8.326497, 8.326373, 8.326280, 8.326231, 8.326236, 8.326308, 8.327059, 8.329405, 8.329279, 8.328513, 8.328162, 8.327693, 8.327464, 8.327160, 8.326899, 8.326721, 8.326660, 8.326656, 8.326768, 8.326886, 8.327037, 8.327209, 8.327158, 8.327161, 8.327185, 8.327239, 8.327322, 8.327442, 8.327574, 8.328226, 8.328796, 8.329184, 8.329717, 8.329955, 8.330110, 8.330285, 8.330782, 8.331267, 8.330564, 8.329241, 8.328986, 8.328760, 8.328565, 8.328351, 8.328113, 8.327991, 8.327836, 8.327728, 8.327725, 8.327751, 8.327941, 8.328014, 8.328076, 8.328105, 8.328209, 8.329228, 8.329634, 8.330093, 8.330368, 8.330683, 8.330780, 8.331074, 8.331145, 8.331525, 8.331698, 8.331776, 8.331790, 8.331733, 8.331604, 8.332141, 8.332452, 8.332688, 8.332678, 8.332716, 8.332766, 8.332833, 8.332992, 8.333628, 8.333871, 8.334020, 8.334761, 8.334941, 8.335546, 8.335655, 8.335753, 8.335783, 8.336230, 8.337095, 8.337525, 8.337830, 8.337898, 8.337994, 8.338356, 8.338735, 8.339091, 8.339439, 8.339605, 8.339754, 8.339960, 8.340984, 8.341287, 8.341604, 8.342297, 8.343026, 8.343188, 8.343387, 8.343800, 8.343999, 8.344228, 8.344626, 8.344987, 8.345244, 8.344067, 8.343897, 8.343478, 8.343434, 48.233826, 48.233507, 48.233136, 48.233047, 48.232736, 48.232474, 48.232308, 48.232240, 48.232159, 48.232035, 48.231953, 48.232359, 48.232428, 48.232808, 48.233214, 48.233466, 48.233591, 48.233716, 48.234339, 48.234482, 48.234602, 48.234725, 48.234928, 48.235017, 48.235174, 48.235261, 48.235374, 48.235773, 48.235892, 48.235965, 48.236121, 48.236511, 48.236666, 48.237071, 48.237768, 48.238040, 48.238277, 48.238614, 48.238903, 48.239111, 48.239218, 48.239282, 48.239431, 48.239520, 48.239788, 48.239877, 48.239909, 48.239921, 48.239899, 48.239861, 48.239830, 48.239843, 48.239894, 48.239999, 48.240348, 48.240520, 48.240610, 48.240688, 48.240735, 48.240733, 48.240701, 48.240594, 48.240159, 48.240071, 48.239922, 48.239790, 48.239676, 48.239262, 48.239242, 48.239282, 48.239183, 48.239291, 48.239412, 48.239533, 48.239537, 48.239765, 48.240034, 48.240109, 48.240167, 48.240221, 48.240340, 48.240413, 48.240542, 48.240653, 48.240784, 48.240900, 48.241600, 48.243751, 48.243950, 48.244376, 48.244574, 48.244856, 48.245012, 48.245358, 48.245553, 48.245716, 48.245828, 48.245872, 48.245903, 48.245936, 48.245996, 48.246012, 48.246275, 48.246468, 48.246573, 48.246687, 48.246774, 48.246841, 48.246879, 48.247012, 48.247227, 48.247339, 48.247518, 48.247633, 48.247749, 48.247912, 48.248171, 48.248544, 48.248910, 48.249508, 48.249649, 48.249815, 48.250022, 48.250340, 48.250731, 48.251026, 48.251499, 48.251938, 48.252047, 48.252163, 48.252560, 48.252757, 48.253089, 48.253425, 48.253685, 48.253911, 48.254049, 48.254158, 48.254306, 48.254523, 48.254627, 48.255072, 48.255147, 48.255442, 48.255713, 48.255939, 48.256163, 48.256782, 48.257332, 48.257903, 48.258317, 48.258782, 48.259292, 48.259438, 48.259503, 48.259567, 48.259649, 48.259820, 48.259922, 48.259967, 48.260235, 48.260331, 48.260712, 48.260829, 48.260994, 48.261319, 48.261624, 48.261892, 48.262004, 48.262411, 48.262441, 48.262434, 48.262321, 48.262012, 48.261771, 48.261581, 48.261778, 48.261830, 48.262052, 48.262661, 48.262828, 48.262945, 48.263073, 48.263176, 48.263176, 48.263132, 48.262990, 48.262970, 48.263014, 48.263142, 48.263166, 48.263242, 48.263207, 48.263233, 48.263529, 48.263552
#>   fare
#> 1    0
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          segments
#> 1 2022.3, 308.9, 247.2, 59.3, 11, Head south on Benatweg, Benatweg, 0, 8, 51.8, 12.4, 6, Continue straight onto Benatweg, Benatweg, 8, 10, 820.5, 65.6, 1, Turn right onto Hölzle, K 5528, Hölzle, K 5528, 10, 34, 785.8, 151.6, 12, Keep left onto Winterbauernhof, Winterbauernhof, 34, 69, 49.1, 11.8, 4, Turn slight left, -, 69, 70, 67.9, 8.1, 1, Turn right, -, 70, 74, 0, 0, 10, Arrive at your destination, on the right, -, 74, 74, 4255.4, 739, 170.4, 20.5, 11, Head northwest, -, 74, 81, 448.5, 53.8, 13, Keep right, -, 81, 87, 317.2, 49.2, 0, Turn left, -, 87, 97, 44.3, 16, 1, Turn right onto Sulzbacher Straße, K 5528, Sulzbacher Straße, K 5528, 97, 101, 447.2, 82.5, 0, Turn left onto Sulzbacher Straße, Sulzbacher Straße, 101, 117, 434.6, 52.1, 0, Turn left, -, 117, 126, 248.1, 29.8, 13, Keep right, -, 126, 134, 286.6, 51.6, 1, Turn right, -, 134, 142, 257.5, 46.4, 12, Keep left, -, 142, 148, 357.9, 64.4, 13, Keep right, -, 148, 158, 12.1, 2.9, 6, Continue straight, -, 158, 159, 573.2, 112.1, 12, Keep left, -, 159, 175, 37.6, 9, 0, Turn left, -, 175, 177, 469.9, 112.8, 12, Keep left, -, 177, 191, 150.3, 36.1, 2, Turn sharp left, -, 191, 195, 0, 0, 10, Arrive at your destination, on the right, -, 195, 195
#>   way_points        summary
#> 1 0, 74, 195 6277.7, 1047.9