A way to access google streetview from R?

醉酒当歌 提交于 2019-11-27 16:47:44

问题


There is a very nice interface to google earth images available via ggmap. For example:

ggmap::get_map(location = c(lon = -95.3632715, lat = 29.7632836), 
               maptype ="satellite",zoom=20)

will return a satellite map image from Google Maps/Earth. On Google Maps website if you zoom a bit more, it switches to streetview. Is there a similar way from R to get the streetview images?

There does seem to be an API, but can't find anything analogous to the ggmap interface in R.


回答1:


My googleway package has a google map widget (and also works with Shiny).

You'll need a valid Google API key to use it

library(googleway)

key <- "your_api_key"

df <- data.frame(lat = -37.817714,
                 lon = 144.967260,
                 info = "Flinders Street Station")

google_map(key = key, height = 600, search_box = T) %>%
    add_markers(data = df, info_window = "info")

## other available methods
# add_markers
# add_heatmap
# add_circles
# add_traffic
# add_bicycling
# add_transit

Satellite

Satellite / Street

Street view

(notice the marker is still there)


Update - Static Street view map

There's also a google_streetview() function that will download a static streetview image (using the Google Street View Static Image API)

google_streetview(location = c(-37.8177, 144.967),
                  size = c(400,400),
                  panorama_id = NULL,
                  output = "plot",
                  heading = 90,
                  fov = 90,
                  pitch = 0,
                  response_check = FALSE,
                  key = key)




回答2:


There's not current an R package that does this, however I can offer you 2 hacks to get the job done.

  1. Use rvest, other scraping packages, or even simply download.file with one of the many independent websites that provide different interfaces/views of streetview data.

    That way you can just parameterize the URI and download the target image.

  2. Use V8 (possibly leveraging browserify) to run the npm package extract-streetview.



来源:https://stackoverflow.com/questions/39197022/a-way-to-access-google-streetview-from-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!