如何使用 Google 卫星视图作为带有 R 的传单中的图块

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

很多问题看起来和我的很相似,但是我找不到适合R的答案。

到目前为止,我以这种方式使用很棒的 R 传单(和 ggmap)包:

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) 

但是如果我想要 Google 卫星作为地图怎么办?

我经历了这个post

但不明白如何使用那里定义的 googleSat 函数。

如果它必须是 google 卫星图像,您可以使用 googleway 包。如果其他卫星图像没问题,您可以在传单中使用 "Esri.WorlImagery" 有或没有 "CartoDB.PositronOnlyLabels":

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")

要使用实际的 Google 地图(附带卫星视图),您可以使用我的 googleway

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)

vignette 提供了更多关于您可以使用地图执行的操作的示例。