Mar 16, 2022 23:25
You're welcome.

It's up to you what you do with the question. You can answer it youself if you want. I probably won't add an answer because I think we've covered everything in this chat and I don't really have time to write it up
Mar 16, 2022 23:22
yes I think so.
Mar 16, 2022 23:08
For example, the distance of the second route is

```
test$routes$legs[[2]]$steps[[1]]$distance
```
Mar 16, 2022 23:07
but the others are avaialble
Mar 16, 2022 23:07
However, the function direction_steps() is a convenience function I wrote, but it only returns the first route.
Mar 16, 2022 23:06
you can get the result of both routes:

```
test$routes$legs[[1]]$steps
test$routes$legs[[2]]$steps
```
Mar 16, 2022 23:06
Actually, that's not correct
Mar 16, 2022 23:03
yes, direction_steps(test)$duration is only the duration of the first route in the response, not the alternatives.
Mar 16, 2022 23:00
that is my understanding
Mar 16, 2022 22:54
The official documentation explains in greate detail what Google gives you in their response - developers.google.com/maps/documentation/directions/…
Mar 16, 2022 22:52
The result test you get from Goolge gives the driving instructions for the entire route. But it's split into legs. In this example there are 5 legs. And each leg has a distance & time.
Mar 16, 2022 22:50
the distance of the entire route is sum(as.numeric(direction_steps(test)$distance$value))
Mar 16, 2022 22:41
gives you the distance of each leg
Mar 16, 2022 22:41
direction_steps(test)$distance
Mar 16, 2022 22:29
The rest of the code will plot them without any modification
Mar 16, 2022 22:29
yes - when you specify alternatives = TRUE in the google_directions() function, if possible it will return alternative routes.
Mar 16, 2022 22:25
direction_steps(test)$duration will specifically show you the time of each leg
Mar 16, 2022 22:25
direction_steps(test) shows you the duration and distance of each leg of the journey
Mar 16, 2022 22:15
i.e., the status of the response from Google
Mar 16, 2022 22:15
but you need to check the status of the result.
Mar 16, 2022 22:15
yes exactly
Mar 16, 2022 22:12
```
df_routes <- data.frame(polyline = direction_polyline(test))

google_map() %>%
add_polylines(data = df_routes, polyline = "polyline")
```
Mar 16, 2022 22:12
The rest of the code should work, just replace df with test
Mar 16, 2022 22:10
whereas in the exmaple on your StackOverflow question you see the $status says "ZERO_RESULTS"
Mar 16, 2022 22:10
you can see in the output the $status says "OK"
Mar 16, 2022 22:09
yes that output suggests the example worked.
Mar 16, 2022 21:53
so I need to know what your df object is.
Mar 16, 2022 21:52
If the result of the google_directions() function is not a valid response from Google, then nothing will work.
Mar 16, 2022 21:52
yes I know what you're trying to do. However, to generate the map, you need to have the result of the google_directions() function, which you have assigned to df using the code df <- google_directions(...).
Mar 16, 2022 21:51
you inserted the object df1 (with the 1). I need to see df because the error you're getting is in this line - direction_polyline(df) - so I need to know what df looks like.
Mar 16, 2022 21:51
is df a valid response from Google? Can you show me what df looks like when you print it in the console?
Mar 16, 2022 21:51
In your original question you create df with this line: df <- google_directions(...). What does this df look like? does the google_directions() funciton return anything and is df valid?
Mar 16, 2022 21:51
what does your df look like?
 

 GMTs

General chat. Please read the FAQ for the rules or if you want...
Dec 16, 2019 02:31
@RonakShah Have we just been answering the same question, but asked from different angles
- https://stackoverflow.com/questions/59349487/is-there-a-faster-rewrite-to-deal-with-missing-xml-attributes
&
- https://stackoverflow.com/questions/59349700/is-there-a-way-to-handle-the-first-lapply-element-differently-or-prepend-it-to
Oct 22, 2019 21:45
Sep 29, 2019 04:07
Sep 17, 2019 05:02
Morning Jaap
Sep 13, 2019 05:53
not a concise one-liner, but I think it works
Sep 13, 2019 05:53
x <- c(2, 3, 4, NA, 2, NA)
s <- x[!is.na(x)]
na_idx <- is.na(x)
x[na_idx] <- sample(s, size = sum(na_idx), replace = T)
x
Sep 3, 2019 05:37
yes, the 0-index catches me out ALL THE TIME when writing Rcpp code. And, it doesn't fail gracefully, it crashes your R & RStudio session...
Sep 3, 2019 05:33
@RomanLuštrik I only spotted it because I've been in that web and come out the other side...

I've started to realise that Google (Maps) is the only system which uses lat/lon, everyone else uses lon/lat
Aug 30, 2019 06:04
close: not reproducible - stackoverflow.com/q/57587789/5977215
Aug 10, 2019 03:24
@thelatemail isn't it just! like waking up one day to find out you're fluent in French
Aug 9, 2019 01:32
might be too snidey, but I had to ask: stackoverflow.com/questions/57422069/…
Jul 15, 2019 02:57
yep
Jul 15, 2019 02:56
yep; must be hard to take if you're a NZ fan