2

I am trying to use get_map and I presume google now requires to access the API using a key since the code in the documentation doesn't work

get_map(location = "texas", zoom = 6, source = "stamen")

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

Suppose my key is XXX, I thought this would work:

get_map(location = "texas", zoom = 6, source = "stamen", api_key = 'XXX')

However, I get the same error as before. I suppose I am passing the key incorrectly since the new error message doesn't show XXX anywhere in the URL.

Dambo
  • 3,318
  • 5
  • 30
  • 79

1 Answers1

4

You need to use register_google(key = "...") in every new session of R. Using api_key = inside the get_map() call does not work.

from: R get_map not passing the api key

automa7
  • 494
  • 4
  • 15
  • 1
    what package is `register_google()`? can't find it using `??register_google`... – Dambo Oct 11 '18 at 16:39
  • 1
    it's from ggmap, the documentation doesn't look up to date, but I could find it on the github repository for ggmap: https://github.com/dkahle/ggmap/blob/master/R/register_google.R – automa7 Oct 11 '18 at 16:43
  • Are you using `ggmap_2.6.1`? I get `Error: 'register_google' is not an exported object from 'namespace:ggmap'` – Dambo Oct 11 '18 at 16:46
  • 2
    the CRAN version is still not up to date with google's new gmap API, from what I read. Try the following command to update it: `devtools::install_github("dkahle/ggmap", ref = "tidyup")` – automa7 Oct 11 '18 at 17:05
  • @automa7 I had to install digest and glue manually in order for that to work but it did! – Robert Tan Nov 04 '18 at 20:58