"RgoogleMaps"包出现错误,HTTP状态为“403 Forbidden”

3

我正在尝试使用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个),Google Maps API的请求是否有限制?

我还尝试使用OpenStreetMaps代替Google Maps,仍然使用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'

我不明白问题出在哪里。有没有其他的包可以使用?基本上,我只需要在地图上放置主要城市和道路的背景,并能够在其上绘制点。
谢谢您的时间。
2个回答

2
您可以尝试使用ggmap这个包,它可以让您从谷歌或osm下载地图,并且您可以使用ggplot2添加数据。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接