【问题标题】:Google Places API: different output for textsearch and nearbysearch (formatted_address missing)Google Places API:文本搜索和附近搜索的不同输出(formatted_address 缺失)
【发布时间】:2020-06-26 11:55:53
【问题描述】:

想使用 Google Places API 附近搜索使用坐标进行反向查找。

我使用nearbysearch 端点。

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.892674%2C151.200727&rankby=distance&type=bar&key=...

缺少的是formatted_address

当尝试改用textsearch 时,我确实得到formatted_address

https://maps.googleapis.com/maps/api/place/textsearch/json?location=-33.892674%2C151.200727&rankby=distance&type=bar&key=...

两者都返回相同的 first place_id 并且看起来非常相似。 我注意到的差异:

  • 文本搜索:formatted_address,空的 opening_hours 包括在内
  • nearbysearch:不包括附近、范围、空的开放时间

如何获取 formatted_address?

更新:我检查了两种类型都应该返回same fields


详情

当按距离和类型搜索时,我想我可以使用nearbysearchtextsearch,但当按突出度搜索时,我将不得不使用nearbysearch,因为textsearch 需要typequery

我想使用的查询(使用附近搜索,所以缺少 formatted_address):

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.892674%2C151.200727&rankby=prominence&radius=500&key=...

完整输出textsearch

    {
      "business_status": "OPERATIONAL",
      "formatted_address": "7 Cope St, Redfern NSW 2016",
      "geometry": {
        "location": {
          "lat": -33.892682,
          "lng": 151.20075
        },
        "viewport": {
          "northeast": {
            "lat": -33.89147812010727,
            "lng": 151.2019769298927
          },
          "southwest": {
            "lat": -33.89417777989272,
            "lng": 151.1992772701072
          }
        }
      },
      "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png",
      "id": "d8b3f319ad00fafd66527b248e450284a53386c2",
      "name": "Arcadia",
      "opening_hours": {
        "open_now": true
      },
      "photos": [
        {
          "height": 3000,
          "html_attributions": [
            "<a href=\"https://maps.google.com/maps/contrib/100984405419723237513\">Colin Hannah</a>"
          ],
          "photo_reference": "CmRaAAAAvnYeIFoCoiiQoyRqKQqpz1yJK71eXM3wYuCiTFTTtj3iwTiIW_z865AfLogqMiEyyBh5GqZoxAcHDmzyE8KelhGEh3C-ggm5LQDGK4zFWxdTNCholvXurq0ce7zLoztgEhBgklqzYxK5jhDhwqB5wuabGhQRUb448z5zV9l7EDSmXLMo5icv1w",
          "width": 4000
        }
      ],
      "place_id": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
      "plus_code": {
        "compound_code": "4642+W7 Redfern, New South Wales",
        "global_code": "4RRH4642+W7"
      },
      "price_level": 2,
      "rating": 4.5,
      "reference": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
      "types": [
        "bar",
        "point_of_interest",
        "establishment"
      ],
      "user_ratings_total": 279
    },

完整输出nearbysearch:

    {
      "business_status": "OPERATIONAL",
      "geometry": {
        "location": {
          "lat": -33.892682,
          "lng": 151.20075
        },
        "viewport": {
          "northeast": {
            "lat": -33.8914789697085,
            "lng": 151.2019760802915
          },
          "southwest": {
            "lat": -33.89417693029149,
            "lng": 151.1992781197085
          }
        }
      },
      "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png",
      "id": "d8b3f319ad00fafd66527b248e450284a53386c2",
      "name": "Arcadia",
      "opening_hours": {
        "open_now": true
      },
      "photos": [
        {
          "height": 3024,
          "html_attributions": [
            "<a href=\"https://maps.google.com/maps/contrib/101220276595662877555\">Milan</a>"
          ],
          "photo_reference": "CmRaAAAA7u4ZpZOddZ8ypuGySsQ1lG0HEX4Ke0DHeYtHYN1gEchx-yf1U-DVLNHVdmFVLoocHbMmWlMVCqcW9oMnpDC4-dw6ObZAovVQG90GpVD3sYeMEpzBB80yjhttjZ1lsIEdEhCzQJane_k8xy-HlI9ZlE9WGhQJ13KgR88Q239e8ocBCt5H0BgpKQ",
          "width": 4032
        }
      ],
      "place_id": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
      "plus_code": {
        "compound_code": "4642+W7 Redfern NSW, Australia",
        "global_code": "4RRH4642+W7"
      },
      "price_level": 2,
      "rating": 4.5,
      "reference": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
      "scope": "GOOGLE",   <===========
      "types": [
        "bar",
        "point_of_interest",
        "establishment"
      ],
      "user_ratings_total": 279,
      "vicinity": "7 Cope Street, Redfern"   <===========
    },

【问题讨论】:

  • 我在文档中读到:以下示例显示了附近搜索响应。文本搜索响应与此类似,只是它返回 formatted_address 而不是 vicinity 属性。

标签: google-places-api


【解决方案1】:

来自@MrUpsidown 的评论指向声明它的documentation

文本搜索响应与此类似,只是它返回 formatted_address 而不是 vicinity 属性

所以,看起来就是这样。

  "formatted_address": "7 Cope St, Redfern NSW 2016",

  "vicinity": "7 Cope Street, Redfern"

【讨论】:

  • 我认为这并不完全正确。我在一些地点进行了测试,“附近”字段的响应只有城市,没有任何其他信息。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-05
相关资源
最近更新 更多