In the 2+ years that have passed since the question was asked, new releases of ggmap
have come out. The package now directly supports caching of downloads. However, when caching Google Maps, there are some conditions one should be aware of; a link to the terms of service appears when ggmap
is attached.
The general get_map
function doesn't have an option for saving the downloaded Google Map tiles, but it can be done with the dedicated get_googlemap
function, by setting archiving = TRUE
. The manual has a note about the user having to accept the Google Maps terms of service (ToS) in this case (too). In my view, the most obvious limitation in the ToS (September 21, 2015) is that the map content must not be stored for more than 30 days. If you accept that, the following code should work.
library(ggmap)
## get_map() as in the question
foo1 <- get_map(location = c(-1.81, 55.655), zoom = 12, maptype = "hybrid")
## This will store map tiles locally, used by any repeated calls
foo2 <- get_googlemap(center = c(-1.81, 55.655), zoom = 12,
maptype = "hybrid", archiving = TRUE, force = FALSE)
identical(foo1, foo2) # TRUE
Other map sources may have more permissive terms or licenses. For example, to use Stamen Maps:
## Get roughly the same area as in the Google map
bbox <- c(left=-1.88, bottom=55.625, right=-1.74, top=55.685)
## Broken in ggmap 2.6.1, try GitHub version (which may have other problems)
foo3 <- get_map(location = bbox, zoom = 13, crop = FALSE,
source = "stamen", maptype = "terrain", force = FALSE)
## Compare the two map sources / types
dev.new()
print(ggmap(foo2))
dev.new()
print(ggmap(foo3))