What's next in googleway: accessors
Due: version 2.4
After a while it gets quite tiresome writing
res[['routes']][['overview_polyline']][['points']]
to access the one piece of information I want from Google's Directions API response.
So I've decided to wirte some "accessor" methods that do the job for me. I've tried to pick the most common elements that I use, but if anyone has other suggestions for elements they'd like quick access to let me know
Example
## until v2.4 is released you'll need the development version
devtools::install_github("SymbolixAU/googleway")
library(googleway)
apiKey <- symbolix.utils::apiKey()
## the accessors work on both lists and JSON (defined via the simplify argument)
lst <- google_directions(origin = "Symbolix, Melbourne, Australia",
destination = "Flinders Street Station, Melbourne"
key = apiKey,
simplify = TRUE)
js <- google_directions(origin = "Symbolix, Melbourne, Australia",
destination = "Flinders Street Station, Melbourne",
key = apiKey,
simplify = FALSE)
## calling the function directly
direction_polyline(lst)
# [1] "rgogFgi~tZjGzBXBAICSRiDNuB^_ ...
direction_polyline(js)
# [1] "rgogFgi~tZjGzBXBAICSRiDNuB^_ ...
## or using the 'access_result' function
access_result(lst, "polyline")
# [1] "rgogFgi~tZjGzBXBAICSRiDNuB^_ ...
For more updates about googleway or any of our open source projects, come and visit us at our github page: https://github.com/SymbolixAU