R language GGMap package installation and use
Ggmap is a map drawing package that calls the Google Maps API via the get_map function.
1 The first attempt went wrong
At the beginning, get_map was used to fetch the map data directly in R. However, an error occurred. The interface to display the function request refused our request (HTTP error code: 403).
library(ggmap) map=get_map(location='San Fransico',maptype='roadmap',zoom=12)
URL:http://maps.googleapis.com/maps/api/staticmap?center=San+Fransico& zoom=12& size=640x640& scale=2& maptype=roadmap& language=en-EN& sensor=false
2 Baidu Discovery
From July 16, 2018, Google will limit the number of API requests, charge fees for exceeding the limit, and make it mandatory for all projects to use the official API Key. Without the API Key, the quality of the map may degrade or the map will not work. The API key must be associated with a credit card, and if the limit is exceeded, Google will start charging from the credit card. The search giant first offered users a $200 a month credit for free. Google slashed the number of free requests, from 25,000 per day to 28,000 per month, or about 1,000 per day, to a quarter of that. Google users who do not apply for a settlement account can only access the interface once a day.
3. Solving problems
So errors occur because of the lack of interface in the request URL key, to apply for a key in the Google maps developer platform:
We also found that we need to associate the credit card account, that is, the account that needs to be cleared by the Google map interface. After completing a series of applications, we found through the URL that to retrieve this function, we need to enable the staticmap KBD> interface. After enabling the interface, we got the KEY KBD> of the staticmap KBD> interface, but we found that the package we just downloaded directly in R could not add the KEY KBD> parameter to the URL. Later, it was found that someone on GitHub had updated the ggmap KBD> package. Then remove the ggmap KBD> package installed previously, install the latest ggmap KBD> package from GitHub, and directly enter the code in R to install:
if(!requireNamespace("devtools")) install.packages("devtools") devtools::install_github("dkahle/ggmap", ref = "tidyup") library(ggmap) register_google(key=”your google map API key”)
Add the KEY parameter to register_google() and call the get_map() function to get the map data. If you get an error message that register_google is not register_google, you have not successfully installed the GGMap package from GitHub.
When I call get_map(), I find an error prompting HTTP request to send REQUEST_DENIED. It was found on StackOverflow that Google map still needs to apply for Geocoding API interface. After applying for the interface, it should be ok to call get_map.
1, ggmap packet address: https://github.com/dkahle/ggmap
2, methods other than Google maps, can also study the openstreetmap:
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- Why can’t I open the R tidyverse package after installation
- Completely solve install_ FAILED_ UPDATE_ Incompatible installation error, the installation package is not consistent with the previous installation package signature on the device
- R language packages installation failed: Error in install.packages: error reading from connection
- R language notes – sample() function
- R language – path setting and working directory modification
- R language error messages and related solutions
- Installing R’s “mvtnorm” package in Windows system: solving the problem of the R package “mvtnorm” is not installed
- Solutions to the failure of R language loading rjava
- Renaming the column name of data frame in R language
- Analysis of R language error replacement has length zero problem
- R language error in hist.default ():’x’must be a value
- R language loading xlsx error error: JAVA_HOME cannot be determined from the Registry
- Solving the problem of saving object set by save() function in R language
- Trivia: How does R language solve Error in ts(x):’ts’ object must have one or more observations
- R language error:‘ namespace:lazyeval There is no exit_ The object is eval
- Error analysis of multiple linear regression in R language model.frame.default
- R language error error: n() should only be called in a data context
- In R language, for loop or array truncation, the following error occurs only 0’s may be mixed with negative subscripts
- The solution of “error in NLS loop more than 50” in R language