rggmap

Problem visualizing maps with staten maps


As I did multiple times, I am trying to import a map of Cyprus using the ggmap function in R:

library("ggmap")
library("ggsn")

leftCY =  412259.3; bottomCY = 3811795;
rightCY = 454399.3; topCY = 3837195;

RHO_map <- get_stamenmap(bbox = c(left    = leftCY, 
                                  bottom  = bottomCY, 
                                  right   = rightCY, 
                                  top     = topCY),
                                  zoom    = 10, 
                                  maptype = "terrain")

However, I get the following error:

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Could not resolve host: tile.stamen.com

I have checked my internet connection and everything is fine. I have seen in some web links Error in curl::curl_fetch_memory(url, handle = handle) with ggmap package

that Tiles are now hosted by Stadia (and require API key) and that I should install from github: remotes::install_github("dkahle/ggmap"). I have installed remotes package, run the suggested command, and rerun the command:

RHO_map <- get_stamenmap(bbox = c(left    = leftCY, 
                                  bottom  = bottomCY, 
                                  right   = rightCY, 
                                  top     = topCY),
                                  zoom    = 10, 
                                  maptype = "terrain")

But I still get the same error, and I am stuck. Is there any suggestion or alternative?


Solution

  • According to the guidelines of stadia website: https://docs.stadiamaps.com/guides/migrating-from-stamen-map-tiles/

    Step 1: Remove the existing version of ggmap from your environment.
    remove.packages("ggmap")
    
    Step 2: Install the devtools package in your R environment.
    install.packages("devtools")
    
    Step 3: Install the Stadia Maps fork of ggmap from GitHub.
    devtools::install_github("stadiamaps/ggmap")
    

    I have created an API key by registering to (free, check video https://www.youtube-nocookie.com/embed/6jUSyI6x3xg) , and I have run the following command

    library("ggmap") 
    register_stadiamaps("API-KEY") 
    us <- c(left = 32.2, bottom = 34.5, right = 34.8, top = 35.8) 
    CY_map <- get_stadiamap(us, zoom = 10, maptype = "stamen_terrain") %>% ggmap()
    

    and it worked.

    Additional comment: Be aware that ggsn is not working with newest R versions, so you need to find alternatives for scalebars and north arrow (now I am facing this problem).