2

Supposed I have a vector contains multiple locations(under longitude and latitude format. I want to find the nearest subway_station by using google_places. However I always get the errors like this:

"Error in validateGeocodeLocation(location) : location must be a vector of a pair of latitude and longitude coordinates.

Code is given in the below.

    location1 %>% head()
[1] "34.450906, -118.227614" "34.123286, -118.758541" "34.545587, -118.420095" "34.090728, -118.127527"
[5] "34.074736, -118.145959" "34.194489, -118.138263"

This works

> subway_station <- google_places(location = c(34.407332, -117.911841),
+                                 rankby = "distance",
+                                 place_type = "subway_station",
+                                 key = key)
The radar argument is now deprecated

try with multiple search

> subway_station <- google_places(location = location1,
+                                 rankby = "distance",
+                                 place_type = "subway_station",
+                                 key = key)
Error in validateGeocodeLocation(location) : 
  location must be a vector of a pair of latitude and longitude coordinates

I guess this issue can be fixed by writing loop but not sure what exactly way to do. Many thanks for helping.

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • I give an example of a loop [in this answer](https://stackoverflow.com/a/48937052/5977215) using `google_distance` in an `lapply`. You should just need to replace the `google_distance` call with your `google_palces` call. – SymbolixAU Jan 31 '19 at 22:06
  • hi SymbolixAU: thanks a lot for your answer. I figured it out by using lapply as stated in your example. however, the rest i need to use another approach cause google_places returns nested lists. – Katty Nguyen Feb 08 '19 at 08:56

0 Answers0