无法在R中使用ggmap和Google Geocoding API进行地理编码;公司防火墙后面 [英] Failure to geocode using the ggmap and Google Geocoding API in R; behind company firewall

查看:217
本文介绍了无法在R中使用ggmap和Google Geocoding API进行地理编码;公司防火墙后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ggmap包中的geocode()函数对R中的地址进行地址解析.我已经在个人计算机上相对轻松地完成了此操作,并想在我的工作计算机上尝试此操作.通常,我应该向Google注册,对ggmap软件包进行库管理,读入我的安全密钥,然后才能使用geocode()函数.但是我得到了错误.见下文:

# Library package
library(ggmap)

# Set key file
gmAPI     <- "key_file.txt"

# Read-in Google API key
gmAPIKey  <- readLines(gmAPI)[1]

# Register key
register_google(key = gmAPIKey)

# Geocode Waco, TX
geocode("waco, texas", output = "latlona")

我收到的不是生成地理编码的输出,而是:

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to maps.googleapis.com port 443: Timed out

或有时:

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to url port ###: Connection refused

注意:我用url port ###替换了错误消息中张贴的实际url/端口,因为我认为这是我的计算机特有的.

我觉得这与我的工作网络有关. 类似的问题已使用httr软件包设置了一些配置,但这些解决方案不适用于我.我可能输入了错误的信息.有帮助吗?

解决方案

我在工作中遇到了类似的问题,实际上,我设法解决了使用httr库中的函数添加一行代码的问题.

我做到了:

library(httr)
set_config(use_proxy(url="http://proxy.mycompanyname.com", port=****))

只需插入代理即可使公司网络中的计算机连接到Internet和需要打开的端口.常用的Web代理服务器端口是3128、8080、6588和80.

希望这会有所帮助!

I am attempting to geocode addresses in R using the geocode() function in the ggmap package. I have done this on my personal computer relatively easily and want to attempt this on my work computer. Generally, I am supposed to register with Google, library the ggmap package, read-in my security key, and then I can use the geocode() function. But I get errors. See below:

# Library package
library(ggmap)

# Set key file
gmAPI     <- "key_file.txt"

# Read-in Google API key
gmAPIKey  <- readLines(gmAPI)[1]

# Register key
register_google(key = gmAPIKey)

# Geocode Waco, TX
geocode("waco, texas", output = "latlona")

Instead of generating geocoded output, I receive:

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to maps.googleapis.com port 443: Timed out

or sometimes:

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to url port ###: Connection refused

Note: I replaced the actual url/port posted in the error message with url port ### as I imagine this is specific to my computer.

I have a feeling this has to do with my work network. Similar questions have set some configuration using the httr package, but those solutions have not worked for me. It's possible I am entering the wrong information. Any help?

解决方案

I have had a similar issue at my work, which I managed to solve adding one line of code with a function from the httr library indeed.

I did:

library(httr)
set_config(use_proxy(url="http://proxy.mycompanyname.com", port=****))

Just insert the proxy through which a computer in your company's network connects to the internet and the port that needs to be opened. Commonly used web proxy server ports are 3128, 8080, 6588 and 80.

Hope this helps!

这篇关于无法在R中使用ggmap和Google Geocoding API进行地理编码;公司防火墙后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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