How to add my Api key into get_map()?


#1

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


How to add my Api key into get_map() function?
#2

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


#3

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


#4

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


#5

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"
  )
#> Source : https://maps.googleapis.com/maps/api/staticmap?center=Dayton&zoom=13&size=640x640&scale=2&maptype=satellite&language=en-EN&key=AIzaSyBmXB5S5_NIqo6lAGH-_U-TbhrQjhOsplU
#> Source : https://maps.googleapis.com/maps/api/geocode/json?address=Dayton&key=AIzaSyBmXB5S5_NIqo6lAGH-_U-TbhrQjhOsplU

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


#6

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