I would like to use the ggmap package to download and display maps. Unfortunately I have some firewall restrictions preventing R from accessing the internet directly. The error I get from get_map is

Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : 
  cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=34.464936,-116.293581&zoom=6&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false'
In addition: Warning message:
In download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :
  cannot open: HTTP status was '403 Forbidden'

Is there a way to manually download and save the map so I can then load and use it with ggmap/ggplot?

Alternatively, is there another way I could use to plot GPS data on maps?

3 Answers 3


I have figured out how to do this. I checked the code for get_map and all it does is download the .png file and use readPNG() method to read it back in. Therefore I was able to manually do the downloading part (using the URL from get_map) to avoid my firewall issues and use readPNG() to read the saved file into R and obtain the ggmap object.


I kind misunderstand your question.

but anyway... First of all you need to download the ggmap library in order to work with it later. Try this code out !

And you can use Google API in order to plot GPS coordinate in a map!

  • Thanks for the link, I had actually seen that post before. The problem is that I don't get to the point where I can save the map objact as .rda file because get_map returns the error mentioned in the question.
    – Lena
    Commented Jul 1, 2015 at 7:05

Depending on what you want to do with the data afterwards, you may want to have a look at the source code of dismo::gmap. As you will notice, the URL of the target image is stored in gurl, and after download, the temporarily saved *.gif is imported into R using raster::raster and inherits all the stuff that's required for subsequent spatial analysis (e.g. extent, projection, optional conversion to an RGB 'RasterStack' object). The only thing you'd have to do is split the function body into two parts which

  1. return gurl which you can then use to manually download the image data from the web, and

  2. import the downloaded data into R and assign the spatial information (requires additional information from the first function, which is possibly redundant, but enables you to perform spatial operations).

Maybe that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.