0

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?

6
  • ggmap#350 discussed the change for the stamen API, and it appears to have been resolved/fixed 5 days ago (I am not a maintainer of ggmap). I don't know the timeline of release to CRAN, though you can try remotes::install_github("dkahle/ggmap") in the interim to see if it works (and I encourage you to report success or failure on that same issue). Commented Nov 6, 2023 at 17:22
  • 1
    I have found the following link: docs.stadiamaps.com/guides/migrating-from-stamen-map-tiles. Indeed, I need to register an API. I guess I will need to register and waiting for their feedback :) Commented Nov 6, 2023 at 17:33
  • 2
    once you get a new API key, if you do a remotes::install_github and get it to work with the new functions, I suggest you come back here and self-answer talking through the API, the remotes::, and all of it, demonstrating the error and the new method working. You are not the first to ask about this, and I suspect over the next few weeks/months we may see more users needing this help. Commented Nov 6, 2023 at 18:07
  • 1
    Hi r2evans. Indeed, you are right. I have created an API key, 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 Commented Nov 6, 2023 at 18:29
  • 1
    Great! Self-answer (and accept your own answer), get a little rep, and have a big impact on fellow ggmap-users who follow in your footprints. Commented Nov 6, 2023 at 18:35

2 Answers 2

3

Update as of 11/20/23: ggmap has been updated on CRAN to version 4.0.0, which includes the get_stadiamap() function. So instead of installing the Stadia Maps fork, just install ggmap again, then register your API key, and you should be good to go!

install.packages("ggmap")
register_stadiamaps("API-KEY")
Sign up to request clarification or add additional context in comments.

1 Comment

Hey all, Stadia Maps cofounder here! Thanks for chiming in @Angela! We've just updated our docs as well to reflect that v4.0.0 is now live on CRAN.
2

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.