I am developing an App using Shiny and leaflet in R. And I need to plot the route obtain with REST API.
I try to obtain Polylines using this:
query <- paste0("&waypoint0=geo!",
lat_usuario,
",",
long_usuario,
"&waypoint1=geo!",
lat_of,
",",
long_of,
"&departure=", fecha,
"&mode=fastest;car;traffic:enabled")
paste0("https://route.api.here.com/routing/7.2/calculateroute.json",
"?app_id=", App_id, "&app_code=", App_code, query) %>%
RCurl::getURL(verbose = FALSE) %>%
RJSONIO::fromJSON() %>%
.[["response"]] %>%
.[["route"]] %>%
.[[1]] %>%
.[["leg"]] %>%
.[[1]] %>%
.[["maneuver"]] %>%
sapply("[[", "position") %>%
return()
But, when I represent using this code:
leafletProxy("mapa", data = values$tabla) %>%
clearShapes() %>%
addPolylines(pol[2,], pol[1,], stroke=0.2)
I obtain that polylines aren't inside the street. As shown in image:
How can I do to plot route inside the streets?
Solved by myself.
The key is include "&routeAttributes=sh" in the query. And, then, we recieve the shapes of route (to be able to plot them).