我正在尝试使用 R 库 Ggmap 对向量进行地理定位。
location_google_10000 <- geocode(first10000_string, output = "latlon",
source = "dsk", messaging = FALSE)
问题是我使用的是“dsk”——数据科学工具包 API——因此它没有像 Google 那样的速率限制(每天限制 2500 个坐标)。但是,当我尝试使用包含超过 2500 个的向量运行时,它会弹出以下消息:
Error: google restricts requests to 2500 requests a day for non-business use.
我尝试使用 1000 个地址的 dsk 运行代码,然后检查是否实际使用了 google 或 dsk api:
> geocodeQueryCheck()
2500 geocoding queries remaining.
由于某种原因,它不允许我使用超过 2500 的“dsk”,但我确信它没有使用 google。
最佳答案
我刚刚遇到了同样的问题并找到了你的帖子。我可以通过将 client
和 signature
值设置为虚拟值来解决此问题,例如
geocode(myLocations, client = "123", signature = "123", output = 'latlon', source = 'dsk')
问题似乎出在地理编码函数的这一部分......
if (length(location) > 1) {
if (userType == "free") {
limit <- "2500"
}
else if (userType == "business") {
limit <- "100000"
}
s <- paste("google restricts requests to", limit, "requests a day for non-business use.")
if (length(location) > as.numeric(limit))
stop(s, call. = F)
userType
在这部分代码的上面设置...
if (client != "" && signature != "") {
if (substr(client, 1, 4) != "gme-")
client <- paste("gme-", client, sep = "")
userType <- "business"
}
else if (client == "" && signature != "") {
stop("if signature argument is specified, client must be as well.",
call. = FALSE)
}
else if (client != "" && signature == "") {
stop("if client argument is specified, signature must be as well.",
call. = FALSE)
}
else {
userType <- "free"
}
因此,如果 client
和 signature
参数为空,userType
将设置为“free”,进而将限制设置为 2,500。通过提供这些参数的值,您将被视为“企业”用户,限制为 100,000。如果假设用户使用“Google”而不是“dsk”作为源,那么这是一个很好的检查,但如果源是“dsk”并且可能应该被覆盖,则过于热心。头脑简单也许是这样的......
if (source == "google") {
if (client != "" && signature != "") {
if (substr(client, 1, 4) != "gme-")
client <- paste("gme-", client, sep = "")
userType <- "business"
}
else if (client == "" && signature != "") {
stop("if signature argument is specified, client must be as well.",
call. = FALSE)
}
else if (client != "" && signature == "") {
stop("if client argument is specified, signature must be as well.",
call. = FALSE)
}
else {
userType <- "free"
}
} else {
userType <- "business"
}
如果为其他源规划了client
或signature
参数,这会导致问题。我将 ping 软件包作者。
关于r - ggmap "dsk"速率限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42282492/