我一直在面临这个问题get_map()
功能 (ggmap
库)在 R 中。
我的代码无需指定 API 密钥即可运行(例如source = "google"
)持续了几个月。然而,该代码在几周前停止工作。我了解到 Google 已强制要求 API 密钥(或者可能他们允许在没有我用尽的 api 密钥的情况下进行一定数量的调用)。
然而,即使在指定了 API 密钥(从 Google Cloud Platform 获取)后,我的代码仍然以相同的方式运行。我什至联系了 Google Cloud 支持,但他们说 API 密钥本身没有任何问题,他们能够在最后调用地图。
我怀疑get_map()
函数没有传递api_key
同时调用谷歌地图。任何有关解决方案的指示将不胜感激。
下面是可重现的代码(失败)。
library(ggmap)
lat <- c(4,41) # India lat boundaries
lon <- c(68,99) # India long boundaries
center = c(mean(lat), mean(lon))
map <- get_map(location = c(lon = mean(lon),
lat = mean(lat)),
api_key = <my api key>,
zoom = 6,
maptype = "terrain",
source = "google",
messaging = TRUE
)
下面是 R 中的错误消息(注意 API 密钥没有被传递)
trying URL 'http://maps.googleapis.com/maps/api/staticmap?center=22.5,83.5&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false'
Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :
cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=22.5,83.5&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false'
In addition: Warning message:
In download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :
cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=22.5,83.5&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false': HTTP status was '403 Forbidden'