R中的GeoCoding时出现连接超时错误 [英] Getting connection timed out error while GeoCoding in R

查看:299
本文介绍了R中的GeoCoding时出现连接超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对R中的几个地址进行地址解析,但会收到超时:连接在10000毫秒后超时"错误.我在办公室防火墙后面,因此也尝试使用代理,但仍然收到相同的错误.

I have to geocode few addresses in R but getting a "Timeout was reached: Connection timed out after 10000 milliseconds" error. I am behind office firewall so tried to use proxy as well but still getting the same error.

当我使用源代码作为"dsk"但不对大多数地址进行地理编码,因此要使用"google"作为源代码时,此方法就可以使用.

This works when I use source as "dsk" but it doesn't geocode most of the addresses hence want to use "google" as source.

下面是我使用的代码.

library(ggmap)
library(curl)

register_google(key = "Have_Entered_My_API_Key_Here")

#Used below code to use proxy...(saw it as a solution in stackoverflow only for working behind firewall..maybe I'm not doing it the correct way?)
library(httr)
set_config(use_proxy(url="10.3.100.207",port=8080))

origAddress <- read.csv("Data_for_Geocoding.csv",header = TRUE,sep = ",",stringsAsFactors = FALSE)

for(i in 1:nrow(origAddress))
{

  result <- geocode(origAddress$Add_to_GeoCode[i], output = "latlona", source = "google",sensor = TRUE)
  origAddress$LONGITUDE[i] <- as.numeric(result[1])
  origAddress$LATITUDE[i] <- as.numeric(result[2])
  # origAddress$ <- as.character(result[3])
}

运行此代码时出现以下错误.
"curl :: curl_fetch_memory(url,handle = handle)中的错误: 达到超时:连接在10000毫秒后超时"

I get the below error when I run this code.
"Error in curl::curl_fetch_memory(url, handle = handle) : Timeout was reached: Connection timed out after 10000 milliseconds"

我需要对成千上万的地址进行地址解析,因此如果有人可以在这里提供帮助,我们将不胜感激.

I have thousands of addresses that I need to geocode so will really appreciate if someone can help here.

推荐答案

花了整整一整天的时间,我很高兴能够解决问题:)从而发布了答案.

如果您收到上面列出的连接超时错误,则应该检查的第一件事是您是否在防火墙后面(如果您在办公室中使用防​​火墙,则很可能是防火墙阻止了您访问Google API)在家里,您可以简单地关闭防火墙).显然,当您处于防火墙之后时,下面的代码就是对地址​​进行地理编码甚至访问google api所需要的代码.

After spending almost entire day on this I'm happy that I was able to unravel the issue :) hence posting the answer.

If you are getting a connection timed out error as I've listed above, the first thing that you should check is if you are behind a firewall (if you are working on it in office, most probably firewall is blocking you from accessing google api. At home you can simply turn off the firewall). Apparently when you are behind a firewall the below piece of code is what you need to geocode or even access google apis.

library(httr)
set_config(
use_proxy(url="Proxy_Add_Here", port=8080, username="username_here",password="password_here")
)

请确保在您的地理编码代码之前添加此代码.

Make sure to add this code before your geocoding code.

注意:请注意,Google Maps API不是免费服务.每月免费提供40,000次对地址解析API的调用(尽管每天的最大请求数上限为2500个),并且超出此上限,每个调用为$ 0.005.

Note: Please note that the Google Maps API is not a free service. There is a free allowance of 40,000 calls to the geocoding API per month (although maximum requests per day are capped at 2500), and beyond that calls are $0.005 each.

PS:如果不确定代理添加...,请按照以下步骤操作.
打开Internet Explorer->工具"->"Internet选项"->连接" ->局域网设置
用户名和密码仅是您的Windows凭据

PS: Follow below steps, if you're not sure about your proxy add....
Open Internet Explorer-->Tools-->Internet Options-->Connections-->LAN Settings
Username and Password are your windows credentials only

这篇关于R中的GeoCoding时出现连接超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆