为什么如果我搜索餐厅的确切地址,places API不会返回该餐厅的相关信息?

时间:2018-09-25 13:32:08

标签: google-maps google-places-api

为什么我要搜索餐厅的确切地址,places API是否不返回该餐厅的相关信息?

例如,这是麦当劳从谷歌搜索中提取的地址:“ 146 Tremont St,Boston,MA 02111”。

如果我在Google Places API上进行搜索,它不会返回这是我期望的麦当劳地址。

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJgdzSI51w44kRROxVqUqfoAg&fields=name,types,website&key=

前端Google搜索:

enter image description here

1 个答案:

答案 0 :(得分:0)

实际上,地点ID ChIJgdzSI51w44kRROxVqUqfoAg的类型为premise,因此它不代表业务,而仅代表地图上的建筑物。

为了解决您的问题,我建议您使用Places API Web服务的Find place请求。这样您就可以发送请求

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=146%20Tremont%20St%2C%20Boston%2C%20MA%2002111&inputtype=textquery&fields=formatted_address,geometry,name,place_id&key=YOUR_API_KEY

此请求将返回以下响应

{
  "candidates":[
    {
      "formatted_address":"146 Tremont St, Boston, MA 02111, USA",
      "geometry":{
    "location":{
      "lat":42.3552225,"lng":-71.0630429
    },
    "viewport":{
      "northeast":{
        "lat":42.35661577989272,"lng":-71.06177427010728
      },
      "southwest":{
        "lat":42.35391612010728,"lng":-71.06447392989273
      }
    }
      },
      "name":"McDonald's",
      "place_id":"ChIJe645PYNw44kR_0ilqhElTKw"
    }
  ],
  "debug_log":{
    "line":[

    ]
  },
  "status":"OK"
}

如您所见,这是麦当劳的理想住所。

我希望这会有所帮助!

相关问题