0

I have a CSV file with 20,000 latitude/longitude coordinates. E.g. a sample:

lat    lon
13.2   100.3
12.3   90.2
24.2   78.8

library(googleway)

google_streetview(
  location = c(13.2, 100.3), # lat/lon coordinates
  size = c(600, 400) # image size

Basically, I want the code above to use the lat/lon coordinates from the first row in the CSV file (which returns a Google Street View image of those coordinates), then loop back through the code and replace the lat/lon coordinates with the second line of the CSV file, and so on.

Does anybody know how to do this?

2 Answers 2

2

You can use the purrr package. Saying your csv is called data:

MyFunction <- function(lat, long){
 google_streetview(location = c(lat,long), size = c(600, 400))
}

purrr::map2(data$lat, data$long, MyFunction)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! How do you save the images that are outputted to a folder on my hard drive?
1

You can use any of the looping functions to iterate over lat and lon values.

For example, using Map -

result <- Map(function(x, y) 
    google_streetview(location = c(x, y), size = c(600, 400)), df$lat, df$lon)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.