SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
232 stars 46 forks source link

nested instructions #183

Closed SymbolixAU closed 6 years ago

SymbolixAU commented 6 years ago

Driving instructions result access needs to extract all list items.

Example

library(googleway)

set_key(read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_API_KEY"))
set_key(read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY"), api = "map")

startPlace = "454 Park Ave S, New York, NY 10016A"
intermediatePlaces = list(stop = "857 2nd Ave, New York, NY 10017",
                          stop = "27 W 47th St, New York, NY 10036",
                          stop = "643 Park Ave, New York, NY 10065",
                          stop = "318 W 39th St, New York, NY 10018")
endPlace = "700 5th Ave, New York, NY 10019"

res = google_directions(origin = startPlace,
                        destination = endPlace,
                        waypoints = intermediatePlaces,
                        optimise_waypoints = TRUE,
                        mode = "driving",
                        alternatives = FALSE,
                        simplify = TRUE)

pl <- direction_polyline(res)
df <- data.frame(polyline = pl)

google_map() %>%
  add_polylines(data = df, polyline = "polyline", stroke_weight = 9)

running

access_result(res,"instructions")

only returns the first list item, but there are more

n = length(res[["routes"]][["legs"]][[1]]["steps"][,1])

for(i in 1:n) print(res[["routes"]][["legs"]][[1]]["steps"][,1][[i]]$html_instructions)

TODO

SymbolixAU commented 6 years ago

I assume the same logic applies for direction_points() too?

SymbolixAU commented 6 years ago

This 'fix' combines everything into a single vector, so it's not clear which instructions belong to which waypoint. Would it be better to keep a separate list for each waypoint?