Google 地点 API:文本搜索和附近搜索的不同输出(formatted_address 缺失)

Google Places API: different output for textsearch and nearbysearch (formatted_address missing)

想使用Google附近的地方API使用坐标进行反向查找。

我使用 nearbysearch 端点。

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

少了formatted_address.

当尝试使用 textsearch 时,我 do 得到 formatted_address.

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

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

如何获得formatted_address?

更新:我检查过,两种类型都应该 return same fields


详情

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

我想使用的查询(使用 nearbysearch,所以缺少 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"   <===========
    },

来自@MrUpsidown 的评论指向 documentation 指出的地方:

A Text Search response is similar, except that it returns a formatted_address instead of a vicinity property

所以,看起来就是这样。

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

  "vicinity": "7 Cope Street, Redfern"