How to use the Google satellite view as tile in leaflet with R
Asked Answered
A

2

11

Many questions seem similar to mine, I could not however find a fitting answer for R.

So far, I use the awesome R leaflet (and ggmap) package that way:

library(ggmap)
library(leaflet)

coord <-geocode('New York')

map.city <- leaflet() %>%
  addTiles('http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png?apikey=68c4cd328d3b484091812a76fae093fd') %>%
setView(coord$lon, coord$lat, zoom = 11) 

But what if I want as a map the Google satellite?

I went through this post

https://mcmap.net/q/296131/-leaflet-map-api-with-google-satellite-layer-duplicate#=

but don't understand how to use the googleSat function defined there.

Aulea answered 21/6, 2017 at 13:49 Comment(5)
If it has to be google satellite imagery you could try the googleway package. If other satellite imagery is ok, you can use "Esri.WorlImagery" in leaflet: map.city <- leaflet() %>% addProviderTiles('Esri.WorldImagery') %>% setView(coord$lon, coord$lat, zoom = 11)Parfleche
Thanks, that can already do the job. The Esri.WorlImagery however does not give the details of the buildings and of the roads. Googleway seems to be an interesting alternative, even though I could not find an equivalent to the controler of leaflet (i.e. how to switch on/off groups)Aulea
I am not sure what you mean with "details of the buildings and the roads". if you refer to the google hybrid map with street names then you could add "CartoDB.PositronOnlyLabels" to at leaste get streest and place names. map.city <- leaflet() %>% addProviderTiles('Esri.WorldImagery') %>% setView(coord$lon, coord$lat, zoom = 11); map.city %>% addProviderTiles("CartoDB.PositronOnlyLabels")Parfleche
@XavierPrudent - (googleway author here) no, you can't control groups on the map directly yet, but it's in the pipelineBarm
Well, given the current status of these packages, I would say TimSalabim and SymbolixAU feel free to turn your comment into an answer, as these are what I am going to use. (btw, impressive package that googleway)Aulea
B
4

To use the actual Google Maps (which comes with satellite view) you can use my googleway package

library(googleway)

apiKey <- 'your_api_key'
mapKey <- 'your_map_key'

newYork <- google_geocode(address = "New York", key = apiKey)

google_map(location = as.numeric(newYork$results$geometry$location), 
           key = mapKey)

enter image description here

The vignette has more examples of what you can do with the maps.

Barm answered 22/6, 2017 at 19:30 Comment(0)
P
19

If it has to be google satellite imagery you could use the googleway package. If other satellite imagery is ok, you can use "Esri.WorlImagery" with or without "CartoDB.PositronOnlyLabels" in leaflet:

library(ggmap)
library(leaflet)

coord <-geocode('New York')

map.city <- leaflet() %>% addProviderTiles('Esri.WorldImagery') %>% 
  setView(coord$lon, coord$lat, zoom = 11)
map.city %>% addProviderTiles("CartoDB.PositronOnlyLabels")
Parfleche answered 22/6, 2017 at 18:58 Comment(0)
B
4

To use the actual Google Maps (which comes with satellite view) you can use my googleway package

library(googleway)

apiKey <- 'your_api_key'
mapKey <- 'your_map_key'

newYork <- google_geocode(address = "New York", key = apiKey)

google_map(location = as.numeric(newYork$results$geometry$location), 
           key = mapKey)

enter image description here

The vignette has more examples of what you can do with the maps.

Barm answered 22/6, 2017 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.