Get_Map Not Passing the API Key (Http Status Was '403 Forbidden')

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.

  1. ggmap is using Google Maps as its standard map source. The Google Maps API that ggmap 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 via register_google(key = "...")

Sample Image


  1. 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)

Sample Image



Related Topics



Leave a reply



Submit