Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 反向地理编码连接问题_R_Reverse Geocoding - Fatal编程技术网

R 反向地理编码连接问题

R 反向地理编码连接问题,r,reverse-geocoding,R,Reverse Geocoding,我试图在一个大数据集上进行反向编码。我正在使用RJSONIO包,并使用googlemapapi获取数据集中给定lat lon的位置。在100或150次成功显示位置信息后,它将显示: Warning message - "In readLines(con) : cannot open: HTTP status was '0 (null)'" 以及: Error:“fromJSON中的错误(粘贴(readLines(con),collapse=”“): 为函数“fromJSON”选择方法时计算参数

我试图在一个大数据集上进行反向编码。我正在使用
RJSONIO
包,并使用googlemapapi获取数据集中给定lat lon的位置。在100或150次成功显示位置信息后,它将显示:

Warning message - "In readLines(con) : cannot open: HTTP status was '0 (null)'"
以及:

Error:“fromJSON中的错误(粘贴(readLines(con),collapse=”“):
为函数“fromJSON”选择方法时计算参数“content”时出错:readLines(con)中出错:无法打开连接

位置最有可能达到使用限制的是,始终存在限制:

除此之外,您还可以(正确地)使用API响应来实现一些限制,特别是在存储这些响应方面:
(特别请参见10.5.d)

您很可能达到了使用限制,但始终存在限制:

除此之外,您还可以(正确地)使用API响应来实现一些限制,特别是在存储这些响应方面:
(特别请参见10.5.d)

我在使用ggmap函数访问google API时遇到了类似的错误。如果您处于速率限制之下,则服务器很可能就是无法响应(任何服务器有时都会这样做,而且您提取的数据越多,您就越有可能遇到这种情况)

如果您的代码中没有任何关于服务器不响应时该做什么的错误处理,那么您的脚本将中断并显示错误消息。简单的解决方案是通过在API返回错误时重新ping API几次来构建一些错误处理(例如,如果API不工作,请重试)

以下是在我的脚本中修复它的内容:

attempt = 1 #start attempt counter

while(attempt != 20) #repeat the API request for up to 20 times
{
  #use try to test for whether or not your API function returns error
  dat.test <- try(PASTE YOUR FUNCTION THAT IS CALLING THE API INTO HERE) 

  if(is(dat.test, 'try-error')) #check if try returned error when pinging the API
  {
    #do these things if an error is returned
    #if there is an error, after completing these items the while loop will continue to the next attempt to reach the API 
    Sys.sleep(1) #wait 1 second
    warning("reattempting google api fetch...") #warn the user
    attempt <- attempt + 1 #update the attempt counter
  } else break #exit the while loop if no error returned (API returned data successfully))
}
trunt=1#启动尝试计数器
而(尝试!=20)#重复API请求最多20次
{
#使用try测试API函数是否返回错误

dat.test我在使用ggmap函数访问google API时也遇到过类似的错误。如果您的速率低于限制,则可能是服务器无法响应(任何服务器有时都会这样做,而且您可能会遇到越多的数据)

如果您的代码中没有任何错误处理,当服务器没有响应时,您的脚本将中断并显示错误消息。简单的解决方案是,在API返回错误时,通过重新ping API几次来构建一些错误处理(例如,如果不起作用,请重试)

以下是在我的脚本中修复它的内容:

attempt = 1 #start attempt counter

while(attempt != 20) #repeat the API request for up to 20 times
{
  #use try to test for whether or not your API function returns error
  dat.test <- try(PASTE YOUR FUNCTION THAT IS CALLING THE API INTO HERE) 

  if(is(dat.test, 'try-error')) #check if try returned error when pinging the API
  {
    #do these things if an error is returned
    #if there is an error, after completing these items the while loop will continue to the next attempt to reach the API 
    Sys.sleep(1) #wait 1 second
    warning("reattempting google api fetch...") #warn the user
    attempt <- attempt + 1 #update the attempt counter
  } else break #exit the while loop if no error returned (API returned data successfully))
}
trunt=1#启动尝试计数器
而(尝试!=20)#重复API请求最多20次
{
#使用try测试API函数是否返回错误

dat.test在给定时间段内可以执行的查询数量是否有任何限制?对于这个问题,我已经设置了一个等待函数,在每次查询后调用该函数并停止执行5秒,仍然存在相同的问题。您应该使用
ggmap::revgeocode
(它调用谷歌的api)谷歌会限制你的评级。这里还有一些包可以使用maps geo/revgeo查找,geocode包有
GnfindnearestAddress
s,所以有很多选项可供选择。而且,你现在有了。正确的批量地理编码将以各种方式花费你美元(无论是API、AWS服务器场还是法律费用/罚款/损害)。在给定的时间段内可以执行的查询数量是否有任何限制?对于这个问题,我已经设置了一个等待函数,在每次查询后调用该函数并停止执行5秒,仍然存在相同的问题。您应该使用
ggmap::revgeocode
(它调用google的api)谷歌会限制你的评级。这里还有一些包可以使用maps geo/revgeo查找,geocode包有
GnfindnearestAddress
s,所以有很多选项可供选择。而且,你现在有了。正确的批量地理编码将以各种方式花费你美元(无论是API、AWS服务器场还是法律费用/罚款/损害)。