2017-05-30 36 views
0

我很抱歉提供了糟糕的屏幕截圖。查看下面的屏幕截圖,我想要一種向Google地圖發送HTTP請求查詢(用藍色圈起來),選擇建議的搜索詞(如果可用)以及以JSON格式返回第一個結果的方法。從那裏,我想解析出這個地方的描述。這在屏幕截圖中以紅色圈出。我搜索了Google Maps和Places API,但找不到足夠的部分來實現解決方案。從R Google地方API抓取地方的描述

編輯:這不會爲現場生產使用。這是我想通過發送用戶輸入名稱的CSV列表來使用的一次性解決方案。

任何援助與此非常感謝。 enter image description here

+0

你有任何(甚至非工作)的代碼嗎?搜索字詞如何「建議」?用戶是否在某處輸入了搜索詞,並且正在寫一個後端,或者您是否編碼了一個已知的地方列表? – Phil

+0

@菲爾否定。我通過CSV列表傳遞用戶輸入的列表。這不是實際使用的任何內容,只需使用舊用戶輸入的數據進行一次性查找即可。 –

回答

4

使用Google Places API時,您可能無法獲取所需的描述(您的紅圈)。

這裏是用我的googleway包(其解析JSON你)

library(googleway) 

apiKey <- 'your_api_key' 

myPlace <- google_places(search_string = "ebm-papst Inc", key = apiKey) 
myPlace 
# $results 
# formatted_address geometry.location.lat geometry.location.lng geometry.viewport.northeast.lat 
# 1 100 Hyde Rd, Farmington, CT 06032, United States    41.69905    -72.86462      41.69995 
# geometry.viewport.northeast.lng geometry.viewport.southwest.lat geometry.viewport.southwest.lng 
# 1      -72.86326      41.69726      -72.86595 
# icon          id   name 
# 1 https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png 0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2 ebm-papst Inc. 
# photos 
# 1 2848, <a href="https://maps.google.com/maps/contrib/116194079529080031684/photos">ebmpapstUSA</a>, CmRYAAAApkJrPj2Esm7Zj3JbYi4GGq4n2_HKa8lD4ajJEiJqreY7g-fqeybxAdN_Y3i12YR7CtlwpzVLOgfGYlKr_dq7lcHywOxFTZ71w5fLAnCwCcckwpwnSN5-ZFHyxatfKDWtEhAiqZ_cUZYZG86txisUiQJuGhSxfmgURHQQsMGrcoCpc_nbthsUnw, 4272 
# place_id rating 
# 1 ChIJk4hBjUWw54kRQ3xwJR2K93g  5 
# reference 
# 1 CmRRAAAAi5th813z3Vidbe399oEgJx0QtweOq395pxBZQIpcNVUUieJPvxOh7_5CiQDY2mzPtoeiN8URmpRWKFLu7OzemOjgFiH3PUT8al7KQGsVF-4uHVL_fMffeF77QzagdsBDEhDEOxx5M5f5c4gvrPFbq3LoGhTnlkNSFopZ2CjGKzl2XrTOIvkz6A 
# types 
# 1 point_of_interest, establishment 

然後,您可以使用place_id場拿到特定地點的更多細節的解決方案。然而,我看不到它說'製造商'在任何地方

myPlaceId <- myPlace$results[1, ]$place_id 

google_place_details(place_id = myPlaceId, key = apiKey) 
# $result 
# $result$address_components 
# long_name  short_name         types 
# 1    100    100       street_number 
# 2  Hyde Road   Hyde Rd         route 
# 3  Farmington  Farmington     locality, political 
# 4 Hartford County Hartford County administrative_area_level_2, political 
# 5  Connecticut    CT administrative_area_level_1, political 
# 6 United States    US      country, political 
# 7   06032   06032       postal_code 
# 8   2835   2835      postal_code_suffix 
# 
# $result$adr_address 
# [1] "<span class=\"street-address\">100 Hyde Rd</span>, <span class=\"locality\">Farmington</span>, <span class=\"region\">CT</span> <span class=\"postal-code\">06032-2835</span>, <span class=\"country-name\">USA</span>" 
# 
# $result$formatted_address 
# [1] "100 Hyde Rd, Farmington, CT 06032, USA" 
# 
# $result$formatted_phone_number 
# [1] "(860) 674-1515" 
# 
# $result$geometry 
# $result$geometry$location 
# $result$geometry$location$lat 
# [1] 41.69905 
# 
# $result$geometry$location$lng 
# [1] -72.86462 
# 
# 
# $result$geometry$viewport 
# $result$geometry$viewport$northeast 
# $result$geometry$viewport$northeast$lat 
# [1] 41.69995 
# 
# $result$geometry$viewport$northeast$lng 
# [1] -72.86326 
# 
# 
# $result$geometry$viewport$southwest 
# $result$geometry$viewport$southwest$lat 
# [1] 41.69726 
# 
# $result$geometry$viewport$southwest$lng 
# [1] -72.86595 
# 
# $result$icon 
# [1] "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png" 
# 
# $result$id 
# [1] "0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2" 
# 
# $result$international_phone_number 
# [1] "+1 860-674-1515" 
# 
# $result$name 
# [1] "ebm-papst Inc." 
# 
# $result$photos 
# height                   html_attributions 
# 1 2848 <a href="https://maps.google.com/maps/contrib/116194079529080031684/photos">ebmpapstUSA</a> 
# photo_reference 
# 1 CmRYAAAAncznMEY_qxszVm2aRsutCo2h_aFJPnQuRetv-qUdo6Z66UCQII6iIEkSXB81k__Ys_earablgBtRq2yFObg0_Ul2xiigSX-fOHiBwrzhKBI4Axz_m72m8u2EVQ3o5lNPEhDGJiqQlUscKYhNCw4a-w4xGhQKhdR8TaZXft29PlD99hWVt62EBA 
# width 
# 1 4272 
# 
# $result$place_id 
# [1] "ChIJk4hBjUWw54kRQ3xwJR2K93g" 
# 
# $result$rating 
# [1] 5 
# 
# $result$reference 
# [1] "CmRRAAAAU9Pt8Bh8VMqqdQ6PRUVxK9X-h6rma8y9BSiqmk4rVcuFPDzJpuX4bdmjLxNhRoOrEDLOKT4CFzNCwT1UXnxl_ezNenzachDjezWp9sGtgt8k5XUjXyF3W_x4ZZJEtqqOEhARfYhWNHUV_gCVTwfpG5OhGhT2pu-L1dTJBho2ekzaO_-_06C-0w" 
# 
# $result$reviews 
# author_name              author_url language 
# 1 David Cuesta https://www.google.com/maps/contrib/117339667056469092013/reviews  es 
# profile_photo_url rating 
# 1 https://lh5.googleusercontent.com/--1xFme4FMZk/AAAAAAAAAAI/AAAAAAAAAA4/apolINU9s78/s128-c0x00000000-cc-rp-mo/photo.jpg  5 
# relative_time_description text  time 
# 1    9 months ago  1471529234 
# 
# $result$scope 
# [1] "GOOGLE" 
# 
# $result$types 
# [1] "point_of_interest" "establishment"  
# 
# $result$url 
# [1] "https://maps.google.com/?cid=8716587461585697859" 
# 
# $result$utc_offset 
# [1] -240 
# 
# $result$vicinity 
# [1] "100 Hyde Road, Farmington" 
# 
# $result$website 
# [1] "http://www.ebmpapst.us/" 
+0

這很漂亮,謝謝。任何想法「製造商」的標籤可能是什麼?我很難相信它通過某個端點不可用。 –

+0

我也找不到它。如果你真的需要那個字符串,也許一些網頁抓取是要走的路? – Phil

+0

@Phil我認爲是的。你能想到替代品嗎?我的一位同事建議Foursquare,但是他們的數據庫遠沒有谷歌那麼完整。 –