README (original) (raw)

install.packages("osrmr")

# install.packages("devtools")
devtools::install_github("ims-fhs/osrmr")
library(osrmr)
nearest(lat = 47, lng = 8, api_version = 5, localhost = FALSE)
#>        lat      lng
#> 1 47.00008 8.003016
viaroute(lat1 = 47.1, lng1 = 8.1, lat2 = 46.9, lng2 = 8.3, instructions = FALSE,
         api_version = 5, localhost = FALSE)
#> [1] 2637.1

encoded_polyline_precision_5 <- rjson::fromJSON(file = "http://router.project-osrm.org/route/v1/driving/8.0997,47.1002;8.101110,47.10430?steps=false&geometries=polyline")$routes[[1]]$geometry
decode_geom(encoded_polyline_precision_5, precision = 5)
#>        lat     lng
#> 1 47.10020 8.09970
#> 2 47.10099 8.09952
#> 3 47.10161 8.10037
#> 4 47.10171 8.10066
#> 5 47.10215 8.10083
#> 6 47.10234 8.10098
#> 7 47.10287 8.10123
#> 8 47.10322 8.10125
#> 9 47.10430 8.10110

For more detailed Information about the components of the ‘osrmr’ package, check out the vignette.