A way to access google streetview from R?
Asked Answered
T

2

8

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.

Tracietracing answered 29/8, 2016 at 0:24 Comment(4)
I don't have an answer, but can I ask what you want to do with the image once you have it via R? ggmap is useful because you can add to the map, but streetview provides an image that you can't really plot on top of. If an answer doesn't come up, I'd consider writing the function to access the API.Nostril
Although, if this is for your earthtones package, I assume you'll want a static image?Theriault
Yeah that was the idea--to let people get the colors of the Great Barrier Reef and some of the other interesting places they've taken streetview camerasTracietracing
@WillCornwell - I've updated googleway to now download a static streetview image - and have added the code to do this in my answer.Theriault
T
13

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

enter image description here

Satellite / Street

enter image description here

Street view

(notice the marker is still there)

enter image description here


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)

enter image description here

Theriault answered 29/8, 2016 at 5:2 Comment(9)
Re. Street View: if you ever need to figure out whether there actually is a Street View panorama at a given location, see code.google.com/p/gmaps-api-issues/issues/detail?id=4823Zolazoldi
Thanks @Zolazoldi - I've updated my package so it can now download static street view imagesTheriault
Could you please tell me why don't get anything when i try your first code ? when i run it i go to viewer but nothing happen , and could you please give an example for the traffic layer please ?Calliope
@Alsqer Sometimes the Rstudio Viewer doesn't display the map properly. Try opening it in a browser by pressing the 'show in new window' button (then you may have to press 'open in browser')Theriault
@Theriault How can i open it in browser ?Calliope
@Alsqer - in the Rstudio Viewer pane, there's a button called 'show in new window' Depending on your settings, this will either open it in a browser, or in a new RStudio window. If a new RStudio window opens, you then need to press 'open in browswer'Theriault
@Alsqer - and to add the traffic layer, just call add_traffic() : google_map(key = key, height = 600, search_box = T) %>% add_markers(data = df, info_window = "info") %>% add_traffic()Theriault
@Theriault Thanks so so much , i really appreciate your help , i'll try to find how to download the photo instead open it in browser , Thanks .Calliope
@Alsqer No worries. I haven't yet worked out why in some Rstudio's the Viewer will show the map, and others it won't. I have two computers with the same version of everything, one shows the map the other doesn't. It's odd.Theriault
D
-4

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.

Donahoe answered 29/8, 2016 at 1:54 Comment(3)
please be advised that directly downloading the streetview images may be against Google's Terms of Use. See google.com/permissions/geoguidelines.html for further reference. (Streetview data is limited to: 1. data is displayed in a website or 2. data is downloaded using the API)Loaning
Thanks for this. This is the key part, I guess: "If you have an academic and non-commercial request for Street View imagery that does not qualify under these guidelines, you may contact us at [email protected] with the details of your project to request permission." I'll check with them before I do anythingTracietracing
There is a way - see my answerTheriault

© 2022 - 2024 — McMap. All rights reserved.