Closed stevecrawshaw closed 3 years ago
Hi Steve,
Thanks, interesting... Could you please attach your output of sessionInfo()
? Will try to check.
The error is related to reading the file, so please also try to update package sf
.
For me the code works:
library(mapsapi)
key = readLines("~/Sync/BGU/key_google")
r = mp_map(
center = "51.2, -2.1",
zoom = 10,
maptype = "roadmap",
key = key,
quiet = TRUE
)
plot(r)
## downsample set to c(2,2)
sessionInfo()
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
##
## locale:
## [1] LC_CTYPE=en_IL LC_NUMERIC=C LC_TIME=en_IL
## [4] LC_COLLATE=en_IL LC_MONETARY=en_IL LC_MESSAGES=en_IL
## [7] LC_PAPER=en_IL LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=en_IL LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] mapsapi_0.4.9
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.6 compiler_4.1.0 pillar_1.6.1
## [4] highr_0.9 bitops_1.0-7 class_7.3-19
## [7] tools_4.1.0 digest_0.6.27 lattice_0.20-44
## [10] evaluate_0.14 lifecycle_1.0.0 tibble_3.1.2
## [13] png_0.1-7 pkgconfig_2.0.3 rlang_0.4.11
## [16] DBI_1.1.1 parallel_4.1.0 yaml_2.2.1
## [19] xfun_0.23 e1071_1.7-6 xml2_1.3.2
## [22] dplyr_1.0.6 stringr_1.4.0 knitr_1.33
## [25] RgoogleMaps_1.4.5.3 generics_0.1.0 vctrs_0.3.8
## [28] classInt_0.4-3 grid_4.1.0 tidyselect_1.1.1
## [31] glue_1.4.2 sf_1.0-0 R6_2.5.0
## [34] fansi_0.4.2 rmarkdown_2.8 sp_1.4-5
## [37] purrr_0.3.4 magrittr_2.0.1 stars_0.5-3
## [40] htmltools_0.5.1.1 ellipsis_0.3.2 units_0.7-1
## [43] abind_1.4-5 KernSmooth_2.23-20 utf8_1.2.1
## [46] stringi_1.6.2 proxy_0.4-25 lwgeom_0.2-6
## [49] crayon_1.4.1
Thanks and Best regards,
Michael
Thanks Michael.. sessionInfo below, removed my api key and replaced with "key" regards steve
Restarting R session...
> wants <- c("sf", "mapsapi", "stars")
> has <- wants %in% rownames(installed.packages())
> if(any(!has)) install.packages(wants[!has])
> lapply(wants, library, character.only=T)
Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
Loading required package: abind
[[1]]
[1] "sf" "stats" "graphics" "grDevices" "utils" "datasets"
[7] "methods" "base"
[[2]]
[1] "mapsapi" "sf" "stats" "graphics" "grDevices" "utils"
[7] "datasets" "methods" "base"
[[3]]
[1] "stars" "abind" "mapsapi" "sf" "stats" "graphics"
[7] "grDevices" "utils" "datasets" "methods" "base"
> r <- mp_map(
+ center = "51.2, -2.1",
+ zoom = 10,
+ maptype = "roadmap",
+ key = "key",
+ quiet = FALSE
+ )
https://maps.googleapis.com/maps/api/staticmap?size=640x640&scale=2¢er=51.2, -2.1&zoom=10&maptype=roadmap&key=key
trying URL 'https://maps.googleapis.com/maps/api/staticmap?size=640x640&scale=2¢er=51.2,%20-2.1&zoom=10&maptype=roadmap&key=key'
Content type 'image/png' length 199266 bytes (194 KB)
downloaded 194 KB
trying to read file: C:\Users\User\AppData\Local\Temp\Rtmp0sc7Pe\file40503ed536f4.png
Error in CPL_read_gdal(as.character(x), as.character(options), as.character(driver), :
file not found
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] stars_0.5-3 abind_1.4-5 mapsapi_0.4.9 sf_1.0-0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 xml2_1.3.2 magrittr_2.0.1 units_0.7-2
[5] tidyselect_1.1.1 R6_2.5.0 rlang_0.4.11 fansi_0.5.0
[9] dplyr_1.0.7 tools_4.1.0 parallel_4.1.0 grid_4.1.0
[13] KernSmooth_2.23-20 utf8_1.2.1 e1071_1.7-7 DBI_1.1.1
[17] ellipsis_0.3.2 class_7.3-19 assertthat_0.2.1 lwgeom_0.2-6
[21] tibble_3.1.2 lifecycle_1.0.0 crayon_1.4.1 purrr_0.3.4
[25] bitops_1.0-7 vctrs_0.3.8 glue_1.4.2 proxy_0.4-26
[29] compiler_4.1.0 pillar_1.6.1 generics_0.1.0 classInt_0.4-3
[33] pkgconfig_2.0.3
Thanks! Can confirm that I'm seeing the issue on Windows 10 too... Will try to figure out how to solve it and will let you know.
Turns out that mode="wb"
is needed in utils::download.file
when downloading a binary file on Windows, otherwise the file is corrupted like you said. Please try to install the development version:
remotes::install_github("michaeldorman/mapsapi")
It should work now:
Hi Michael, apologies for delay in replying - i have been away. That all works fine now. Thanks for resolving so quickly. steve
Great, thanks for letting me know and glad to hear it works for you!
Thanks for the package. I am trying mp_map with a simple example but keep getting error:
The file is saved, but when I open e.g. in gimp it returns a corruption error.
The url generated by the function does return the map i expect in the browser. thanks steve