2017-10-12 6 views
1

에서 추출합니다. Google지도 API의 주변 검색을 기반으로 은행에서 데이터를 가져옵니다. 어떤 경우에는 하나 이상의 은행을 끌어 당깁니다 (일부 은행은 서로 가깝기 때문에). 각 은행에 대한 자세한 정보를 검색하기 위해 두 번째 api pull (장소 ID 기반)을 수행 할 수 있도록 반환 된 각 개별 JSON 객체를 추출하려면 어떻게해야합니까? 내 코드는 다음과 같습니다.JSON의 Google API 요청 행을 R

require(jsonlite) 
require(utils) 


plcUrl <- "https://maps.googleapis.com/maps/api/place/nearbysearch/json?" 
key <- "myKEY" 
location <- paste0("41.0272, -81.51345") 
address <- "XXXXXXXXXXXXXXXXX" 
type <- "bank" 
radius <- "500" 
name = "XXXXX" 
strurl <- as.character(paste(plcUrl , 
          "&location=",location, 
          "&address=",address, 
          #"&name=",name, 
          "&radius=",radius, 
          "&type=",type, 
          "&key=",key, 
          sep="")) 
setInternet2(TRUE) 
rd <- fromJSON(URLencode(strurl)) 
rd$results$place_id 

답변

3

googleway v2.4부터 Google API 쿼리의 특정 요소에 액세스하는 메소드를 추가했습니다.

library(googleway) 

key <- "your_api_key" 

## search places 
res <- google_places(location = c(41.0272, -81.51345), 
        key = key, 
        place_type = "bank", 
        radius = 500) 


## get the place_id values using the `place` method to extract the ids 
place(res) 
# [1] "ChIJDe7R2HQqMYgRvqoszlV6YTA" "ChIJDQwLUXMqMYgR-3Nb2KFhZZ0" 

## query the details 
details <- google_place_details(place_id = place(res)[1], key = key) 

details$result$opening_hours 
# $open_now 
# [1] FALSE 
# 
# $periods 
# close.day close.time open.day open.time 
# 1   1  1600  1  0900 
# 2   2  1600  2  0900 
# 3   3  1600  3  0900 
# 4   4  1600  4  0900 
# 5   5  1800  5  0900 
# 6   6  1300  6  0900 
# 
# $weekday_text 
# [1] "Monday: 9:00 AM – 4:00 PM" "Tuesday: 9:00 AM – 4:00 PM" "Wednesday: 9:00 AM – 4:00 PM" "Thursday: 9:00 AM – 4:00 PM" 
# [5] "Friday: 9:00 AM – 6:00 PM" "Saturday: 9:00 AM – 1:00 PM" "Sunday: Closed" 
+0

아직 개원 시간은 없습니까? 그 사실로 인해 나는 당신의 패키지에서 멀리 떨어져있었습니다. 그것이 내가 원하는 것입니다. 감사! – CooperBuckeye05

+0

@ CooperBuckeye05 - 확실히 내 편집을 참조하십시오 – SymbolixAU

+0

끝내 주셔서 감사합니다. – CooperBuckeye05