r语言 - 包"RgoogleMaps" HTTP 状态出错,'403 Forbidden'



我正在尝试使用RgoogleMaps制作地图。我的代码曾经在今天早上工作,但现在我收到此错误:

map.lyon <- GetMap(center=c(45.77338,4.856039), zoom = 15, destfile = "tile1.png", maptype = "mobile")
Error in download.file(url, destfile, mode = "wb", quiet = TRUE) :
  cannot open URL 'http://maps.google.com/maps/api/staticmap?center=45.77338,4.856039&zoom=15&size=640x640&maptype=mobile&format=png32&sensor=true'
    In addition: Warning message:
    In download.file(url, destfile, mode = "wb", quiet = TRUE) :
      cannot open: HTTP status was '403 Forbidden'

我今天早上做了很多地图(可能大约200张),谷歌地图API的请求有限制吗?

我还尝试使用 OpenStreetMaps 而不是 Google 地图,总是使用 RgoogleMaps 包,但这也不起作用(尽管它只是在网站上找到的代码的简单示例),错误非常相似,这是代码:

library(RgoogleMaps)
lat_c<-51.47393
lon_c<-7.22667
bb<-qbbox(lat = c(lat_c[1]+0.01, lat_c[1]-0.01), lon = c(lon_c[1]+0.03, lon_c[1]-0.03))
OSM.map<-GetMap.OSM(lonR=bb$lonR, latR=bb$latR, scale = 20000, destfile="bochum.png")

这是我运行它时所拥有的:

   > library(RgoogleMaps)
   > lat_c<-51.47393
   > lon_c<-7.22667
   > bb<-qbbox(lat = c(lat_c[1]+0.01, lat_c[1]-0.01), lon = c(lon_c[1]+0.03, lon_c[1]-0.03))
   > OSM.map<-GetMap.OSM(lonR=bb$lonR, latR=bb$latR, scale = 20000, destfile="bochum.png")
[1] "http://tile.openstreetmap.org/cgi-bin/export?bbox=7.19637,51.46383,7.25697,51.48403&scale=20000&format=png"
trying URL 'http://tile.openstreetmap.org/cgi-bin/export?bbox=7.19637,51.46383,7.25697,51.48403&scale=20000&format=png'
 Error in download.file(url, destfile, mode = "wb", quiet = FALSE) : 
 cannot open URL 'http://tile.openstreetmap.org/cgi-bin/export?bbox=7.19637,51.46383,7.25697,51.48403&scale=20000&format=png'
 In addition: Warning message:
 In download.file(url, destfile, mode = "wb", quiet = FALSE) :
   cannot open: HTTP status was '403 Forbidden'

我不明白问题是什么。我可以使用其他软件包吗?基本上,我只需要有一张包含该地区主要城市和道路的背景地图,并能够在其上方绘制点。

谢谢你的时间。

你可以试试ggmap包,它允许你从google或osm下载地图,你可以使用ggplot2添加数据。

如果您使用 RStudio:1 - 转到工具2 - 全局选项3 - 包装4 - 在 CRAN 镜像下:单击更改 - 选择全局 (CDN) - RStudio(您根据您所在的位置选择不同的选项)

最新更新