You need to use register_google(key = "..."
) in every new session of R. Using api_key =
inside the get_map()
call does not work.
updated: 2018-12-24 for ggmap 2.7.904 and current Google Cloud API
Step-by-Step Tutorial
1. Update to newest version of ggmap
require(devtools)
devtools::install_github("dkahle/ggmap", ref = "tidyup")
2. Activate your Google API key for all APIs in the Google Cloud Console
-
APIs you need: Maps Static and Geocoding
-
Enable billing in the general settings.
3. Load ggmap and register key
library(ggmap)
register_google(key = "...") # copied directly from Google Console via 'copy' button
4. Plot default map
ggmap(get_googlemap())
5. Plot with location name (Geocoding)
ggmap(get_map("Hannover, Germany"))
If you get an error here (e.g., Forbidden 403) you most probably have not activated your key for the right APIs. Tutorial to troubleshoot geocoding
6. Plot with longitude and latitude
ggmap(get_map(location=c(16.3738,48.2082), zoom=13, scale=2))