1

I've run a large set of google_reverse_geocode calls through the Google Maps API using the googleway library and I've got a couple of questions.

My initial call is as follows:

loczip <- lapply(seq(nrow(LonLat)), function(i){
google_reverse_geocode(location = c(LonLat$`Centerlat`[i],LonLat$`Center Long`[i]),
                       result_type=c("street_address"),
                       location_type="rooftop",
                       key = "**API KEY HERE**",
                       simplify = TRUE)
})

Where LonLat is a list with 12,207 observations and 2 variables, Center lat and Center Long. This call is based on an answer I found here

My outputs are in a large list of 12,207 elements. So far I've been having issues exporting this data into a clean format.

I'm wondering if there's a better way to format the output, so instead of a list the values I get are in a data frame or matrix. Baring that, I'm wondering if there's a good way to parse the existing output into a data frame or something similarly useful. My end goal is to export this data to a .csv.

An example of my output is as follows:

> loczipShort[5]
[[1]]
[[1]]$results
address_components
1 1309, South Cushman Avenue, Central Tacoma, Tacoma, Pierce County,
Washington, United States, 98405, 3527, 1309, S Cushman Ave, Central
Tacoma, Tacoma, Pierce County, WA, US, 98405, 3527, street_number,
route, neighborhood, political, locality, political,
administrative_area_level_2, political, administrative_area_level_1,
political, country, political, postal_code, postal_code_suffix
formatted_address geometry.location.lat
geometry.location.lng geometry.location_type

1 1309 S Cushman Ave, Tacoma, WA 98405, USA              47.24899            
-122.4566                ROOFTOP
geometry.viewport.northeast.lat geometry.viewport.northeast.lng
geometry.viewport.southwest.lat

1                        47.25034                       -122.4552                       
47.24764
geometry.viewport.southwest.lng                    place_id     
types

1                       -122.4579 ChIJccNG8BJVkFQRUvDLCQI9Qtc
street_address
[[1]]$status
[1] "OK"

Another complication is that while using the "rooftop" location type there are some outputs that contain "ZERO RESULTS" so I want to make sure I either return an empty row for those, or some other kind of filler so I can clean those out later.

More background about this project: I have paid API access so making the 12k calls isn't the issue. For some reason my account is not set up such that I can use ggmaps and its revgeocode() function, even with ggmaps 2.7, and changing my account status is currently not an option.

Please let me know if there's anything I can clarify, and thank you in advance!

Edit:

df <- structure(list(Longitude = c(-122.4568254, -122.4568254, -122.4568254, 
-122.4568254), Latitude = c(47.249256, 47.249256, 47.24917901, 
47.24910202)), .Names = c("Longitude", "Latitude"), class = "data.frame", row.names = c(NA, 
-4L))

4 sample points from my data. The first two should yield ZERO RESULTS and the second paid should have data. As I understand it the first two have ZERO RESULTS because the points aren't within the "rooftop" range of any canonical address.

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
Jai Paton
  • 11
  • 2
  • please see [my answer here](https://stackoverflow.com/a/46516973/5977215) for some development I've been doing regarding accessing API responses. Regarding the 'better format than a list' - this will be tricky because the response is JSON, and not all responses contain the same elements, so a 'flat' table is not always the 'best'. Having said that, there are libraries such as `tidyjson` that will attempt this for you. – SymbolixAU Oct 03 '17 at 20:55
  • Thank you for your quick response. I'll take a closer look at working with the JSON string. So far when I set simplify = FALSE I'm still getting a "list" of outputs but more toward the JSON format. It could be that it is a JSON string but that's just what r classifies it as. I suppose my overall question would be if there's a good way to pull specific values like address and neighborhood over a large set. I'm still pretty new to r so I'm still working on how to properly manipulate my data. – Jai Paton Oct 03 '17 at 21:32
  • Can you update your question with a couple/three of rows of your `LonLat` data frame that demonstrate both ZERO Results, and actual results? – SymbolixAU Oct 04 '17 at 20:49
  • Updated. As I mention in the edit the first two should have ZERO RESULTS and the second paid should have information. The second two, I believe, are close enough that they yield the same canonical data. – Jai Paton Oct 04 '17 at 23:31
  • An Update: My head of engineering made the calls directly to the Google API and parsed out the JSON via jq. Thank you for your help. – Jai Paton Oct 05 '17 at 18:46
  • for what it's worth, in the answer I linked to, those helper functions that extract the information are using `jqr` (the R implementation of jq) – SymbolixAU Oct 05 '17 at 20:41

0 Answers0