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" #> $ 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 3 #> .. .. ..$ segments :List of 1 #> .. .. .. ..$ :List of 3 #> .. .. .. .. ..$ distance: num 5479 #> .. .. .. .. ..$ duration: num 804 #> .. .. .. .. ..$ steps :List of 15 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 247 #> .. .. .. .. .. .. ..$ duration : num 59.4 #> .. .. .. .. .. .. ..$ type : int 11 #> .. .. .. .. .. .. ..$ instruction: chr "Head south on Benatweg" #> .. .. .. .. .. .. ..$ name : chr "Benatweg" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 0 9 #> .. .. .. .. .. ..$ :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] 9 12 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 1685 #> .. .. .. .. .. .. ..$ 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] 12 71 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 264 #> .. .. .. .. .. .. ..$ duration : num 31.7 #> .. .. .. .. .. .. ..$ type : int 1 #> .. .. .. .. .. .. ..$ instruction: chr "Turn right" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 71 80 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 302 #> .. .. .. .. .. .. ..$ duration : num 36.2 #> .. .. .. .. .. .. ..$ type : int 0 #> .. .. .. .. .. .. ..$ instruction: chr "Turn left" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 80 92 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 536 #> .. .. .. .. .. .. ..$ duration : num 64.3 #> .. .. .. .. .. .. ..$ type : int 0 #> .. .. .. .. .. .. ..$ instruction: chr "Turn left" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 92 105 #> .. .. .. .. .. .. [list output truncated] #> .. .. ..$ summary :List of 2 #> .. .. .. ..$ distance: num 5479 #> .. .. .. ..$ duration: num 804 #> .. .. ..$ way_points: int [1:2] 0 181 #> .. ..$ geometry :List of 2 #> .. .. ..$ coordinates: num [1:182, 1:2] 8.34 8.34 8.34 8.34 8.34 ... #> .. .. ..$ type : chr "LineString" #> $ bbox : num [1:4] 8.33 48.23 8.35 48.26 #> $ metadata:List of 6 #> ..$ attribution : chr "openrouteservice.org | OpenStreetMap contributors" #> ..$ service : chr "routing" #> ..$ timestamp : num 1.63e+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 "6.6.1" #> .. ..$ build_date: chr "2021-07-05T10:57:48Z" #> .. ..$ graph_date: chr "2021-10-03T10:50:45Z" #> ..$ system_message: chr "Preference 'fastest' has been deprecated, using 'recommended'."
# customized options ors_directions(coordinates, profile="cycling-mountain", elevation=TRUE)
#> <ors_directions> #> List of 4 #> $ type : chr "FeatureCollection" #> $ 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 5 #> .. .. ..$ ascent : num 121 #> .. .. ..$ descent : num 135 #> .. .. ..$ segments :List of 1 #> .. .. .. ..$ :List of 5 #> .. .. .. .. ..$ distance: num 5207 #> .. .. .. .. ..$ duration: num 1272 #> .. .. .. .. ..$ steps :List of 16 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 889 #> .. .. .. .. .. .. ..$ duration : num 321 #> .. .. .. .. .. .. ..$ type : int 11 #> .. .. .. .. .. .. ..$ instruction: chr "Head southwest" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 0 25 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 10.1 #> .. .. .. .. .. .. ..$ duration : num 2 #> .. .. .. .. .. .. ..$ 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] 25 26 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 813 #> .. .. .. .. .. .. ..$ duration : num 163 #> .. .. .. .. .. .. ..$ type : int 12 #> .. .. .. .. .. .. ..$ instruction: chr "Keep left onto Sulzbacher Straße, K 5528" #> .. .. .. .. .. .. ..$ name : chr "Sulzbacher Straße, K 5528" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 26 56 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 264 #> .. .. .. .. .. .. ..$ duration : num 59.3 #> .. .. .. .. .. .. ..$ type : int 1 #> .. .. .. .. .. .. ..$ instruction: chr "Turn right" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 56 65 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 302 #> .. .. .. .. .. .. ..$ duration : num 67.9 #> .. .. .. .. .. .. ..$ type : int 0 #> .. .. .. .. .. .. ..$ instruction: chr "Turn left" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 65 77 #> .. .. .. .. .. ..$ :List of 6 #> .. .. .. .. .. .. ..$ distance : num 536 #> .. .. .. .. .. .. ..$ duration : num 118 #> .. .. .. .. .. .. ..$ type : int 0 #> .. .. .. .. .. .. ..$ instruction: chr "Turn left" #> .. .. .. .. .. .. ..$ name : chr "-" #> .. .. .. .. .. .. ..$ way_points : int [1:2] 77 90 #> .. .. .. .. .. .. [list output truncated] #> .. .. .. .. ..$ ascent : num 121 #> .. .. .. .. ..$ descent : num 135 #> .. .. ..$ summary :List of 2 #> .. .. .. ..$ distance: num 5207 #> .. .. .. ..$ duration: num 1272 #> .. .. ..$ way_points: int [1:2] 0 166 #> .. ..$ geometry :List of 2 #> .. .. ..$ coordinates: num [1:167, 1:3] 8.34 8.34 8.34 8.34 8.34 ... #> .. .. ..$ type : chr "LineString" #> $ bbox : num [1:6] 8.33 48.23 659.9 8.35 48.26 ... #> $ metadata:List of 5 #> ..$ attribution: chr "openrouteservice.org | OpenStreetMap contributors" #> ..$ service : chr "routing" #> ..$ timestamp : num 1.63e+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 "6.6.1" #> .. ..$ build_date: chr "2021-07-12T01:00:30Z" #> .. ..$ graph_date: chr "2021-09-01T23:24:21Z"
# 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")
#> segments #> 1 2023.1, 309, 247.3, 59.4, 11, Head south on Benatweg, Benatweg, 0, 9, 51.8, 12.4, 6, Continue straight onto Benatweg, Benatweg, 9, 12, 820.8, 65.7, 1, Turn right onto Hölzle, K 5528, Hölzle, K 5528, 12, 39, 835.2, 163.4, 12, Keep left onto Winterbauernhof, Winterbauernhof, 39, 80, 67.9, 8.1, 1, Turn right, -, 80, 84, 0, 0, 10, Arrive at your destination, on the right, -, 84, 84, 4261.2, 728.1, 170.4, 20.4, 11, Head northwest, -, 84, 89, 448.5, 53.8, 13, Keep right, -, 89, 95, 312.9, 45.4, 0, Turn left, -, 95, 109, 5.3, 1.3, 5, Turn slight right onto Sulzbacher Straße, Sulzbacher Straße, 109, 110, 48.8, 7.6, 1, Turn right onto Sulzbacher Straße, K 5528, Sulzbacher Straße, K 5528, 110, 114, 446.8, 82.4, 0, Turn left onto Sulzbacher Straße, Sulzbacher Straße, 114, 132, 434.6, 52.2, 0, Turn left, -, 132, 143, 248.2, 29.8, 13, Keep right, -, 143, 151, 286.7, 51.6, 1, Turn right, -, 151, 161, 257.6, 46.4, 12, Keep left, -, 161, 168, 370.1, 67.4, 13, Keep right, -, 168, 180, 573.2, 112.1, 12, Keep left, -, 180, 197, 37.6, 9, 0, Turn left, -, 197, 200, 469.9, 112.8, 12, Keep left, -, 200, 214, 150.6, 36.1, 2, Turn sharp left, -, 214, 219, 0, 0, 10, Arrive at your destination, on the right, -, 219, 219 #> summary way_points #> 1 6284.3, 1037.1 0, 84, 219 #> geometry #> 1 8.344268, 8.344147, 8.344098, 8.343945, 8.343853, 8.343320, 8.343098, 8.342861, 8.342711, 8.342328, 8.342045, 8.341843, 8.341711, 8.341383, 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.338488, 8.338386, 8.338316, 8.338225, 8.338175, 8.338114, 8.337902, 8.337248, 8.337061, 8.336925, 8.336708, 8.336422, 8.336235, 8.336131, 8.335913, 8.335414, 8.335115, 8.335074, 8.335007, 8.334985, 8.334962, 8.334947, 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.330940, 8.330020, 8.329920, 8.329823, 8.329540, 8.328893, 8.328703, 8.328396, 8.328169, 8.328164, 8.327920, 8.327629, 8.327338, 8.326496, 8.326373, 8.326280, 8.326231, 8.326236, 8.326308, 8.327059, 8.329405, 8.329363, 8.329279, 8.328513, 8.328162, 8.328095, 8.327693, 8.327464, 8.327295, 8.327160, 8.327086, 8.326899, 8.326781, 8.326721, 8.326628, 8.326629, 8.326886, 8.327037, 8.327127, 8.327241, 8.327158, 8.327161, 8.327239, 8.327322, 8.327441, 8.327574, 8.327702, 8.328226, 8.328795, 8.329184, 8.329480, 8.329717, 8.329955, 8.330110, 8.330285, 8.330781, 8.330975, 8.331267, 8.330564, 8.329866, 8.329241, 8.328986, 8.328760, 8.328565, 8.328433, 8.328351, 8.328113, 8.327991, 8.327836, 8.327728, 8.327725, 8.327751, 8.327941, 8.328048, 8.328105, 8.328142, 8.328209, 8.328516, 8.329228, 8.329634, 8.330093, 8.330368, 8.330524, 8.330683, 8.330780, 8.331073, 8.331145, 8.331250, 8.331525, 8.331697, 8.331776, 8.331790, 8.331733, 8.331604, 8.332141, 8.332452, 8.332688, 8.332678, 8.332716, 8.332766, 8.332832, 8.332991, 8.333627, 8.333839, 8.333871, 8.334020, 8.334545, 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.339604, 8.339748, 8.339754, 8.339960, 8.340984, 8.341287, 8.341604, 8.342296, 8.343026, 8.343188, 8.343387, 8.343800, 8.343999, 8.344228, 8.344626, 8.344987, 8.345244, 8.344865, 8.344067, 8.343897, 8.343478, 8.343433, 48.233826, 48.233507, 48.233435, 48.233136, 48.233047, 48.232736, 48.232473, 48.232307, 48.232240, 48.232159, 48.232090, 48.232035, 48.231953, 48.232074, 48.232359, 48.232428, 48.232808, 48.233214, 48.233466, 48.233591, 48.233716, 48.234339, 48.234481, 48.234602, 48.234725, 48.234928, 48.235174, 48.235261, 48.235374, 48.235773, 48.235892, 48.235965, 48.236121, 48.236510, 48.236666, 48.236809, 48.237071, 48.237411, 48.237640, 48.237768, 48.237947, 48.238277, 48.238563, 48.238614, 48.238752, 48.238828, 48.238903, 48.238994, 48.239111, 48.239218, 48.239282, 48.239431, 48.239519, 48.239787, 48.239877, 48.239909, 48.239921, 48.239899, 48.239860, 48.239830, 48.239843, 48.239893, 48.239999, 48.240348, 48.240519, 48.240610, 48.240688, 48.240735, 48.240733, 48.240701, 48.240594, 48.240159, 48.240071, 48.239922, 48.239789, 48.239675, 48.239262, 48.239242, 48.239250, 48.239282, 48.239183, 48.239291, 48.239412, 48.239533, 48.239537, 48.239765, 48.239960, 48.240109, 48.240340, 48.240413, 48.240542, 48.240653, 48.240784, 48.240900, 48.241600, 48.243751, 48.243836, 48.243950, 48.244376, 48.244574, 48.244615, 48.244855, 48.245012, 48.245189, 48.245358, 48.245423, 48.245553, 48.245657, 48.245716, 48.245822, 48.245870, 48.245936, 48.245996, 48.246012, 48.246020, 48.246275, 48.246468, 48.246687, 48.246774, 48.246841, 48.246879, 48.246901, 48.247012, 48.247227, 48.247339, 48.247433, 48.247518, 48.247633, 48.247749, 48.247912, 48.248171, 48.248308, 48.248544, 48.248910, 48.249234, 48.249508, 48.249649, 48.249815, 48.250022, 48.250216, 48.250340, 48.250730, 48.251026, 48.251499, 48.251938, 48.252046, 48.252163, 48.252560, 48.252888, 48.253424, 48.253535, 48.253685, 48.253748, 48.253911, 48.254049, 48.254158, 48.254306, 48.254409, 48.254523, 48.254627, 48.255072, 48.255146, 48.255237, 48.255442, 48.255713, 48.255938, 48.256163, 48.256781, 48.257332, 48.257903, 48.258317, 48.258781, 48.259292, 48.259438, 48.259503, 48.259566, 48.259649, 48.259820, 48.259908, 48.259922, 48.259967, 48.260150, 48.260235, 48.260331, 48.260712, 48.260829, 48.260994, 48.261319, 48.261624, 48.261891, 48.262004, 48.262411, 48.262441, 48.262433, 48.262320, 48.262012, 48.261771, 48.261581, 48.261778, 48.261829, 48.261830, 48.262052, 48.262661, 48.262828, 48.262945, 48.263073, 48.263176, 48.263176, 48.263132, 48.262989, 48.262970, 48.263014, 48.263142, 48.263166, 48.263242, 48.263233, 48.263207, 48.263233, 48.263529, 48.263552