2017-10-15 124 views
0

我正在編寫一個代碼,以便根據用戶使用Node.js提示並調用Google的Places API來獲取地點附近的位置。通話如下。如何使用google地方獲取電話號碼API

https://maps.googleapis.com/maps/api/place/textsearch/json?query=garage+near+corner+of+ 
fifth+avenue+NY&key=myApiKey 

基本上我在這裏尋找附近的第五大道紐約的車庫。我得到的迴應如下。

{ 
    "html_attributions": [], 
    "next_page_token": "CqQCHgEAAKUUxRRzEF_vLKTGE5CLg-kBW7K8ot040l4zcsNHEByHpvjrhZZVOWcyCiPBbtErrX9QZNQ9dZQXCaxynnaJonFjF23_PPhWAmIfIRbY40E4gFioA5o4Gm3_OjkOicROypQQlArqaf2ub6vGoMwDKU1eP8m6SFmiMwm1cS_mghR0IWJ2Q9mH5jqpPtWJd2ENX3VCrDPeoOfhaxHAg3DIG7-eh7WYMlT9r6KAERCok-fXnjI49QVrezZYK52aCY3qeLSPLeXonrE2a79jfEdV1EhpBvb4fV2SB2oysCc_xK_Kv3FW6-Ir3WK2jXslrfRvFk7sIRxtgqAlZ2xCZ43oi7DeTl5733S5j4pbFZQHgsg9grLApa_H_wTN2xN1K9UsEhIQOf7B6Gnh668FPRTZe4X78BoUOMt8UiiVZR-YDJDb5AwyME7yYuY", 
    "results": [ 
     { 
      "formatted_address": "39 W 23rd St, New York, NY 10010, United States", 
      "geometry": { 
       "location": { 
        "lat": 40.742537, 
        "lng": -73.99092399999999 
       }, 
       "viewport": { 
        "northeast": { 
         "lat": 40.7437215802915, 
         "lng": -73.9896989197085 
        }, 
        "southwest": { 
         "lat": 40.7410236197085, 
         "lng": -73.99239688029151 
        } 
       } 
      }, 
      "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", 
      "id": "b075e432a0597a31ceaf3062747999291d8d8cf7", 
      "name": "Park-it 23-24 Operating Corp", 
      "opening_hours": { 
       "open_now": false, 
       "weekday_text": [] 
      }, 
      "place_id": "ChIJJalOaKRZwokRNLnbupB5UrY", 
      "reference": "CmRSAAAA-HGHWnLtBTIkRA7MlY1sjb8jDIxJQokfHSfQ_MWcLLM7lNB_MlUOwO0TcrQO8IYbUz1_l-HiehIwZ3hvg3sHEAiV-ZYpNL11gY15gz6hQsUFFKEkkfqoo_9R1PzVBd9CEhD7AxenKMzgH0LK4lNPFC8GGhSKMjd_5UnZyA3VRJrRYaw79QcxVg", 
      "types": [ 
       "parking", 
       "point_of_interest", 
       "establishment" 
      ] 
     } 
. 
. 
. 
. 
} 

我收到的結果是沒有phoneNumber可用。如果我使用正確的API來獲取附近的地點,以及如何獲得電話號碼以及結果,可否請讓我知道。

謝謝

回答

1

目前,無法從Places API搜索響應中獲取電話號碼。爲了獲得電話號碼,您必須爲每個單獨的地點ID執行地點詳細信息請求。

E.g. https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJJalOaKRZwokRNLnbupB5UrY&key=YOUR_API_KEY

的響應將包含字段formatted_phone_numberinternational_phone_number

... 
"adr_address":"39 W 23rd St, New York, NY 10010-4295, USA", 
"formatted_address":"39 W 23rd St, New York, NY 10010, USA", 
"formatted_phone_number":"(212) 727-0141", 
"geometry":{ 
    "location":{ 
    "lat":40.742537,"lng":-73.99092399999999 
    }, 
    "viewport":{ 
    "northeast":{ 
     "lat":40.7437215802915,"lng":-73.9896989197085 
    }, 
    "southwest":{ 
     "lat":40.7410236197085,"lng":-73.99239688029151 
    } 
    } 
}, 
"icon":"https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", 
"id":"b075e432a0597a31ceaf3062747999291d8d8cf7", 
"international_phone_number":"+1 212-727-0141", 
"name":"Park-it 23-24 Operating Corp", 
... 

我也看到有人試圖向在谷歌問題跟蹤早在2011年這個功能請求,但谷歌關閉了此功能要求爲不可行

https://issuetracker.google.com/issues/35820573

隨意創造Google issue tracker新的功能要求,希望谷歌可以偵察它在2017年。

+0

感謝您的寶貴信息:-) – user3872094

相關問題