【发布时间】:2015-02-17 12:01:02
【问题描述】:
我最近一直在玩 ggmap 包中的 mapdist 函数。
对于少量查询它对我来说很好,但对于大量查询(仍然低于 2,500 个限制)它会失败,我不知道为什么。
我有一位老同事尝试过这个脚本,他们得到的结果和我一样(他们在不同的组织,使用不同的计算机,在不同的网络等)。
这是我的测试脚本,它一次又一次地运行相同的请求,以查看它在失败之前设法通过了多少查询。它有一段时间一直返回 129,最近又开始返回 127(尽管这个数字在某个测试中仍然是一致的)。
请注意,尽管这重复了相同的邮政编码,但我尝试了类似的方法,随机选择目标邮政编码并得到相同的结果。
library("ggmap")
# Setup ----------
no.of.pcd.to.check <- 500
a <- rep("SW1A 1AA",no.of.pcd.to.check) # Use a repeating list of the same postcode to remove it as a causal factor
b <- rep("WC2H 0HE",no.of.pcd.to.check) # As above
test.length <- 5 # How many iterations should the test run over
# Create results dataframe ----------
# and pre-set capacity to speed up the for loop
results.df <- data.frame(
Iteration=seq(1:test.length),
Result=as.integer(rep(0,test.length)),
Remaining=as.integer(rep(0,test.length)))
# Run the test ----------
for(i in 1:test.length){
x <- distQueryCheck() # Get remaining number of queries pre submission
try(mapdist(a, b, mode="driving", output="simple",override_limit=TRUE))
y <- distQueryCheck() # Get remaining number of queries post submission
query.use <- (x-y) # Difference between pre and post (ie number of successful queries submitted)
print(paste(query.use, "queries used"))
results.df[i,"Result"] <- query.use # Save successful number of queries for each test iteration
results.df[i,"Remaining"] <- y
}
如果能提供任何关于我在哪里出错的见解,我将不胜感激。
【问题讨论】:
-
这有点推测,但是,查看
mapdist(...)的代码,该函数会测试请求 url 是否大于 2048 个字符。如果是,mapdist(...)以 1/2 的邮政编码递归调用自身,直到请求中的字符数 -
另外,您应该知道 terms of service 将您限制为每个查询
标签: r google-maps-api-3 ggmap