我一直在使用googleway软件包使用place\u type键检索信息,但我一直坚持使用60 results limit restriction.
我正在try 一种稍微不同的方法来解决这个限制:分而治之.
为了检索60个结果,我正在使用提供的卓越解决方案here,当我执行单数搜索时,一切都很好.
提前致谢,危地马拉致以最良好的问候
这里是我的纯文本坐标文件:
coords
"14.5446147628533, -90.84266666418"
"14.5538523714673, -90.84266666418"
这是我的代码:
###Preamble packages##
library(tidyverse)
library(googleway)
### load coordinates, plain text
dfCoords <- read.csv("~/coords.txt", sep="")
##Added For-loop begin##
for (i in dfCoords$coords) {
#### Original script begin ###
place_type <- "store"
key <- c("API Key")
radius <- 100
location <- i
format_res <- function(res) {
setNames(
cbind(
googleway::access_result(res, "coordinates"),
googleway::access_result(res, "place_name")
)
, c("lat", "long", "name")
)
}
do_search <- function(place_type, key, location, radius, page_token = NULL) {
google_places(
place_type = place_type,
location = location,
key = key,
radius = radius,
page_token = page_token
)
}
full_search <- function(place_type, key, location, radius) {
counter <- 0
page_token <- NULL ## can start on NULL because it means we're doing the first query
is_another_page <- TRUE
while( is_another_page ) {
res <- do_search(place_type, key, location, radius, page_token)
if( res$status == "OK" ) { ## check a valid result was returned
if( counter == 0 ) {
df <- format_res( res )
} else {
df <- rbind(df, format_res( res ) )
}
counter <- counter + 1
}
page_token <- res[["next_page_token"]]
is_another_page <- !is.null( page_token )
Sys.sleep(3) ## Sleep the function before the next call because there's a time limit
}
return(df)
}
df <- full_search(place_type, key, location, radius)
##Original script ends
}
##Added for loop end
str( df )