【问题标题】:Google Places API: retrieve restaurant in RomeGoogle Places API:检索罗马的餐厅
【发布时间】:2017-05-21 09:27:53
【问题描述】:

即使我将研究限制在postal_code:00100|country:IT(00100 = 罗马邮政编码,IT = 意大利),我也很难理解 Postman 为何要让我在美国返回餐厅

这是我的 GET:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&components=postal_code:00100|country:IT&key=MYSECRETKEY

我哪里错了?

【问题讨论】:

标签: json get google-places-api postman


【解决方案1】:

Places API 文本搜索不支持组件过滤。

看官方文档,没有components参数可用:

https://developers.google.com/places/web-service/search#TextSearchRequests

要使您的结果有偏差,您应该使用locationradius 参数。

只有 Geocoding API 支持组件过滤。所以你可以分两步解决这个问题。

  • 使用地理编码 API 获取邮政编码的位置
  • 从第一步开始使用 Places API 文本搜索和位置搜索餐厅

例如

获取邮政编码 00100 的位置

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A00100%7Ccountry%3AIT&key=YOUR_API_KEY

现在使用坐标 41.9228369,12.5014301 搜索半径 5 公里内的餐厅

https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&location=41.9228369%2C12.5014301&radius=5000&key=YOUR_API_KEY

希望这会有所帮助!

【讨论】:

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