我正在编写一个代码,以便根据用户使用Node.js的提示并拨打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来获取附近的地方以及如何获得电话号码以及结果,请告诉我。
由于
答案 0 :(得分:2)
目前,无法从Places API搜索响应中获取电话号码。要获取电话号码,您必须为每个地点ID执行“商家信息”详细信息请求。
E.g。 https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJJalOaKRZwokRNLnbupB5UrY&key=YOUR_API_KEY
回复将包含字段formatted_phone_number
和international_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年的Google问题跟踪器中为此提交功能请求,但Google已将此功能请求视为不可行
https://issuetracker.google.com/issues/35820573
欢迎在Google issue tracker中创建新的功能请求,希望Google可能会在2017年重新考虑它。