Question

I am trying to make maps with RgoogleMaps. My code used to work this morning but now I get this error :

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'

I made a lot of maps this morning (maybe about 200), is there a limitation in the requests of Google Maps API ?

I also tried to use OpenStreetMaps instead of Google Maps, always with RgoogleMaps package but this does not work either (although it's just a simple example of code found on a website), the error is very similar, here is the code :

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")

And here is what I have when I run it :

   > 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'

I don't understand what the problem is. Is there another package I could use? Basically I just need to have a background map with major cities and roads in the area and be able to plot points above it.

Thank you for your time.

Was it helpful?

Solution

You can try the package ggmap, it lets you download maps from google or osm and you can add data using ggplot2.

OTHER TIPS

If you use RStudio: 1 - go to Tools 2 - Global Options 3 - Packagees 4 - under CRAN mirror: click on change - you select Global (CDN) - RStudio (you select different option depend on where you at)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top