简体   繁体   中英

R: Error in get_map() from ggmap

I am trying to plot a simple map in R using function get_map() for a certain location. Following is my code:

eg

get_map(location = "texas", zoom = 10, source = "google")

I've tried different parameters. The error I'm getting is following:

Error in aperm.default(map, c(2, 1, 3)) : 
perm' is of wrong length 3 (!= 2)

What is exactly happening in the background & how do I fix it? I checked all the possible blogs I could, no one seems to get this error.

Please help!

This error occurs due to the base url. In CRAN version , the base url is not secure. Use dev version of this package from {github} instead & function runs fine. Use devtools::install_github(""dkahle/ggmap") to install library from github

I had the same problem and updating my google api key worked out.

I'm with ggmap from github but facing de same problem here...

> devtools::install_github("dkahle/ggmap")
Skipping install of 'ggmap' from a github remote, the SHA1 (7b696967) has not changed since last install.
  Use `force = TRUE` to force installation
> library(ggmap)
Carregando pacotes exigidos: ggplot2
Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
Please cite ggmap if you use it! See citation("ggmap") for details.
> register_google(key = "MyKey")
> geocode("parque do ibirapuera")
Source : https://maps.googleapis.com/maps/api/geocode/json?address=parque+do+ibirapuera&key=xxx-mKaA7Kw
# A tibble: 1 x 2
    lon   lat
  <dbl> <dbl>
1 -46.7 -23.6
> get_map(location = "texas", zoom = 10, source = "google")
Source : https://maps.googleapis.com/maps/api/staticmap?center=texas&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-mKaA7Kw
Error in aperm.default(map, c(2, 1, 3)) : 
  primeiro argumento inválido: deve ser um array
Além disso: Warning message:
In get_googlemap(center = location, zoom = zoom, maptype = maptype,  :
  HTTP 400 Bad Request
> 

Navigate directly to the URL generated, and you should see a different error message that might be more informative:

https://maps.googleapis.com/maps/api/staticmap?center=31,-97&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=<INSERT_YOUR_KEY>

In my case, it said my API key was not valid for this API, although up to that point the error just said the same thing about

Error in aperm.default(map, c(2, 1, 3)) : 
     invalid first argument, must be an array

and

HTTP 400 Bad Request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM