【问题标题】:Why if I search the exact address for a restaurant, does the places API not return the associated information for that restaurant?为什么如果我搜索餐厅的确切地址,places API 不会返回该餐厅的相关信息?
【发布时间】:2018-09-25 13:32:08
【问题描述】:

为什么如果我搜索餐厅的确切地址,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-maps google-places-api


    【解决方案1】:

    确实,地点 ID ChIJgdzSI51w44kRROxVqUqfoAg 有一个类型 premise,所以它不代表企业,而只是地图上的建筑物。

    为了解决您的问题,我建议使用来自 Places API 网络服务的 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"
    }
    

    如您所见,这应该是麦当劳的地方。

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-08
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多