【发布时间】:2018-04-07 08:34:06
【问题描述】:
我正在尝试对大型数据集进行反向地理编码。我正在使用RJSONIO 包并使用 Google 地图 API 来获取数据集中给定纬度的位置。在成功显示位置信息 100 或 150 次后,它正在显示:
Warning message - "In readLines(con) : cannot open: HTTP status was '0 (null)'"
和:
Error : "Error in fromJSON(paste(readLines(con), collapse = "")) :
error in evaluating the argument 'content' in selecting a method for function 'fromJSON': Error in readLines(con) : cannot open the connection"
location<-function(latlng){
latlngStr <- gsub(' ','%20', paste(latlng, collapse=","))
library("RJSONIO") #Load Library
#Open Connection
connectStr <- paste('http://maps.google.com/maps/api/geocode/json?sensor=false&latlng=',latlngStr, sep="")
con <- url(connectStr)
data.json <- fromJSON(paste(readLines(con), collapse=""))
close(con)
data.json <- unlist(data.json)
if(data.json["status"]=="OK")
address <- data.json["results.formatted_address"]
print (address)
}
可能的原因是什么以及如何解决问题?
我使用的是 R 版本 3.2.1 和 Ubuntu 14.10。
【问题讨论】:
-
在给定时间段内可以执行的查询数量是否有任何限制?
-
对于那个问题,我已经设置了一个等待函数,在每次查询后调用并暂停执行 5 秒,仍然存在同样的问题。
-
你应该使用
ggmap::revgeocode(它调用谷歌的api),谷歌会限制你的速率。还有一些包可以使用 HERE 地图地理/revgeo 查找blog.corynissen.com/2014/10/… 和地理编码包有GNfindNearestAddress,所以有很多选项可供选择。而且,您现在拥有nominatim。适当的批量地理编码会以一种或另一种方式花费您(无论是 API、AWS 服务器场或法律费用/罚款/损害的前期费用)。
标签: r reverse-geocoding