How to pass a google API key to get_maps?
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
Google static Maps always returning 403 when a key is provided
I finally sorted things out, the problem was that I was subscribing to the "Google Maps API v2" service instead of "Static Maps API".
Switching them in the API console fixed the problem.
Using ggmap to create maps and persistent error R
So there are two things here that are causing problems.
ggmap
is using Google Maps as its standard map source. The Google Maps API thatggmap
is connecting to needs a registered Static Maps API key. You can get a (free) API key here, though note that you will have to register billing to be able to use one (if you don't Maps API requests will return an error). Once you have that set up, you will need to register it in every new session viaregister_google(key = "...")
- The Google Maps API that
ggmap
is connecting to needs lon/lat coordinates (e.g., location = c(-75.1636077,39.9524175)) to fully run.
So, the full code for you would be:
library(rjson)
library(digest)
library(glue)
library(devtools)
if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library(ggmap)
register_google(key = "...", # your Static Maps API key
account_type = "standard")
map <- get_map(location = c(-75.1636077,39.9524175), zoom = 13)
ggmap(map)
Related Topics
Handling Dates When We Switch to Daylight Savings Time and Back
Should I Use a Data.Frame or a Matrix
How to Randomize (Or Permute) a Dataframe Rowwise and Columnwise
How to Override a Non-Visible Function in the Package Namespace
Displaying a Greater Than or Equal Sign
R Gotcha: Logical-And Operator for Combining Conditions Is & Not &&
Comparing Two Vectors in an If Statement
Factors in R: More Than an Annoyance
Saving Multiple Ggplots from Ls into One and Separate Files in R
Adding Labels to Ggplot Bar Chart
Why Is Using '<<-' Frowned Upon and How to Avoid It
Create a Matrix of Scatterplots (Pairs() Equivalent) in Ggplot2
Linear Regression with a Known Fixed Intercept in R
Dplyr::Group_By_ with Character String Input of Several Variable Names
Emulate Split() with Dplyr Group_By: Return a List of Data Frames
Different Legends and Fill Colours for Facetted Ggplot
Specifying Column Names in a Data.Frame Changes Spaces to "."