How to add my Api key into get_map()?

How to add my Api key into get_map() function?
get_map(Dayton, .....,
api_key = 'my api key' ) doesn't work....

Hi, can you provide a bit more details about what you are trying to do? Where does get_map function comes from, for example?

Hello there,
I'm trying to add my api key into get_map function, because otherwise it will occur "HTTP status was '403 Forbidden'" error. I tried to assign api_key <- 'my api key' , but seems it doesn't work....

Here is my mapping code:

Dayton.map <- ggmap(get_map("Dayton",
zoom = 13, scale = "auto",
maptype = "satellite",
source = "google",
api_key),
extent="device",
legend="topright"
)

I'm trying to add my api key into get_map function, because otherwise it will occur "HTTP status was '403 Forbidden'" error. I tried to assign api_key <- 'my api key' , but seems it doesn't work....

Here is my mapping code:

Dayton.map <- ggmap(get_map("Dayton",
zoom = 13, scale = "auto",
maptype = "satellite",
source = "google",
api_key),
extent="device",
legend="topright")

If you download the development version of ggmap from GitHub, there is a function that saves your Google API key and uses it in subsequent calls to the API via ggmap.

# install dev version of ggmap
devtools::install_github("dkahle/ggmap")

library(ggmap)
#> Loading required package: ggplot2
#> Google Maps API Terms of Service: http://developers.google.com/maps/terms.
#> Please cite ggmap if you use it: see citation("ggmap") for details.

# save api key
register_google(key = "YOUR_API_KEY")

# check if key is saved
has_goog_key()
#> [1] TRUE

ggmap(
  ggmap = get_map(
    "Dayton",
     zoom = 13, scale = "auto",
     maptype = "satellite",
     source = "google"),
  extent = "device",
  legend = "topright"
  )

Created on 2018-10-09 by the reprex package (v0.2.1)

3 Likes

Thank you so much for your valuable advice! Now I can successfully get a crime density map:)

A post was merged into an existing topic: Issues in installation of dev version of ggmap library in R