Is something wrong with the ggmap and mapview packages in R?
Google has tightened controls on API access to Google Map products. This means that you now need a Google API key to use ggmap().
There are a few steps involved:
- Visit https://console.cloud.google.com and create a new project.
- Set up an API key: navigation menu -> APIs and services -> Library
-> Maps Static API - Create a billing account and enable billing for the API key. You will need to provide credit card details but don't need to pay anything. It is a good idea to set some limits on how the API key can be used to prevent theft -- if you are not sharing your code, the easiest way is probably to limit it to requests from your own IP address.
- Enable static maps for this api key.
- In R, run
register_google("<your API key>")
. You will need to run this
for every new session in which you will use ggmap(). I have added it to my .Rprofile.
Good luck!
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
Creating "Word" Cloud of Phrases, Not Individual Words in R
How to Set Bin Width with Geom_Bar Stat="Identity" in a Time Series Plot
Shiny - Custom Warning/Error Messages
Follow-Up: Generalizing a Data.Frame Subsetting Function 2
Adding a New Column to Matrix Error
Getting Table() to Return Zeroes in R
Preventing Incosistent Spacing/Bar Widths in Geom_Bar with Many Bars
Transform One Column from Categoric to Binary, Keep the Rest
Distance Calculation on Large Vectors [Performance]
Adding Manual Legend in Ggplot
How to Add a Legend for the Secondary Axis Ggplot
Take the Subsets of a Data.Frame with the Same Feature and Select a Single Row from Each Subset
R Shiny - Ui.R Seems to Not Recognize a Dataframe Read by Server.R
In R, How to Split Timestamp Interval Data into Regular Slots