I found this solution and try it, How to show path and distance on map with leaflet, shiny apps?
but when I run the code
library(leaflet)
library(osrm)
route = osrmRoute(c(115.6813467,-32.0397559), c(150.3715249,-33.8469759),overview = "simplified")
# route_simple = osrmRoute(c(115.6813467,-32.0397559), c(150.3715249,-33.8469759), overview = 'simplified')
route_summary = osrmRoute(c(115.6813467,-32.0397559), c(150.3715249,-33.8469759), overview = FALSE)
leaflet() %>% addTiles() %>%
addMarkers(c(115.6813467,150.3715249), c(-32.0397559,-33.8469759))%>%
addPolylines(route$lon,route$lat,
label = paste(round(route_summary[1]/60), 'hr - ', round(route_summary[2]), 'km'),
labelOptions = labelOptions(noHide = TRUE))
there is not any route$lon and route$lat found and it gives me this error
Error in validateCoords(lng, lat, funcName, mode = "polygon") : addPolylines requires non-NULL longitude/latitude values
Could you please help me?
Try to show route on map using leaflet
In current version of
osrm,osrmRoute()returns ansfobject which can be passed toleaflet():Created on 2024-03-12 with reprex v2.1.0