我有一个应用程序,用户可以在其中提供特定地址,应用程序将返回以后用于对数据进行分组的地理编码。
代码片段简单如下:
library(ggmap)
geocode("2020 walnut street pa")
当我在本地计算机上运行时,这非常有效。我得到以下输出:
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false
lon lat
1 -75.17508 39.95034
然而,当我在闪亮的服务器上运行相同的代码时,我收到以下错误:
> library(ggmap)
Loading required package: ggplot2
> geocode("2020 walnut street pa")
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false
lon lat
1 NA NA
Warning messages:
1: In readLines(connect, warn = FALSE) :
URL 'http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false': status was 'Couldn't connect to server'
2: In geocode("2020 walnut street pa") :
geocoding failed for "2020 walnut street pa".
if accompanied by 500 Internal Server Error with using dsk, try google.
>
我想这与某些权限问题有关,但我不知道需要做什么。任何人都可以帮我理解这里需要做些什么吗?
答案 0 :(得分:0)
我能够找到解决方案。 在闪亮的应用程序(global.R)中,我设置了
(if
(string-match "Microsoft"
(with-temp-buffer (shell-command "uname -r" t)
(goto-char (point-max))
(delete-char -1)
(buffer-string)))
(message "Running under Linux subsystem for Windows")
(message "Not running under Linux subsystem for Windows")
)
这解决了代理问题,服务器可以与google api连接。