使用 Google 个地点的 placeId 的分层和翻译结果

Hierarchical & translated results of a placeId using Google Places

我正在使用 Google 地点搜索地点(也许我需要 Google 地图才能达到我想要的目标):

https://maps.googleapis.com/maps/api/place/details/json?placeid=Eh9SdWUgU3RhbmlzbGFzLCBDb2xtYXIsINem16jXpNeq&language=hi&key=myKey

回复:

{
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "Rue Stanislas",
            "short_name" : "Rue Stanislas",
            "types" : [ "route" ]
         },
         {
            "long_name" : "Colmar",
            "short_name" : "Colmar",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Haut-Rhin",
            "short_name" : "Haut-Rhin",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "Grand Est",
            "short_name" : "Grand Est",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "फ़्रांस",
            "short_name" : "FR",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "68000",
            "short_name" : "68000",
            "types" : [ "postal_code" ]
         }
      ],
      "adr_address" : "\u003cspan class=\"street-address\"\u003eRue Stanislas\u003c/span\u003e, \u003cspan class=\"postal-code\"\u003e68000\u003c/span\u003e \u003cspan class=\"locality\"\u003eColmar\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eFrance\u003c/span\u003e",
      "formatted_address" : "Rue Stanislas, 68000 Colmar, France",
      "geometry" : {
         "location" : {
            "lat" : 48.0799554,
            "lng" : 7.3526162
         },
         "viewport" : {
            "northeast" : {
               "lat" : 48.0813043802915,
               "lng" : 7.353965180291502
            },
            "southwest" : {
               "lat" : 48.0786064197085,
               "lng" : 7.351267219708498
            }
         }
      },
      "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
      "id" : "e5f239bd54d6e0156e898767330506c2e45735a5",
      "name" : "Rue Stanislas",
      "place_id" : "ChIJn4hibt5lkUcRrCcB7Govsis",
      "reference" : "CmRbAAAAygsTgSHpHE4OFcumAyXCPTWOY9qepgdVPY0_CI72WMFxhSQsGZ6bgEUyDr7i8lAbiEYjFD4QQC4v-M2LfFZKmRiq8IpBnxCkUqf0kUN2cE8I68Fb6o7eAit2N_33jLBWEhBBalp6JYpcV78RkMWeAGrvGhToTkaPAXWlULgE8fOuVtkx5hf_6g",
      "scope" : "GOOGLE",
      "types" : [ "route" ],
      "url" : "https://maps.google.com/?q=Rue+Stanislas,+68000+Colmar,+France&ftid=0x479165de6e62889f:0x2bb22f6aec0127ac",
      "utc_offset" : 120,
      "vicinity" : "Colmar"
   },
   "status" : "OK"
}

我对这个回复有一些问题: 1. 我需要每个地点的 ID:locality, administrative_area_level_2, administrative_area_level_1。 为了获得它们 - 我是否必须再向 google 个地方发送 3 个请求?如果我必须 - 我如何在不使用 id 的情况下获得特定位置的精确结果(如果我必须使用 text-searchHaut-Rhin 我也许可以获得更多结果)?

  1. 即使发送 language=hi 我也只翻译了国家/地区。

  2. 科尔马也属于 Alsace 地区,但在任何地方都没有被提及。

你的问题好像有点笼统,不过我会尽量解答你的疑惑。

  1. 你是对的,响应中的地址组件目前没有公开每个组件的地点 ID,因此你必须执行额外的请求才能获取地址组件的地点 ID。

请注意,在 Google 问题跟踪器中有一个功能请求,要求在响应中添加每个地址组件的地点 ID

https://issuetracker.google.com/issues/35827596

随时为该功能请求加注星标以添加您的投票并订阅进一步的通知。

同时,您可以执行 reverse geocoding 请求获取您所在位置的坐标,以获取位置、管理区域 1 和管理区域 2 的位置 ID。在您的示例中,该位置的坐标是 48.0799554,7.3526162.让我们创建反向地理编码请求以获取有关位置和行政区域的信息:

https://maps.googleapis.com/maps/api/geocode/json?latlng=48.0799554%2C7.3526162&result_type=administrative_area_level_1%7Cadministrative_area_level_2%7Clocality&key=YOUR_API_KEY

此请求将 return

  • 地点科尔马,地点 ID ChIJz8Fw9t9lkUcRZulsYT5-XeM

  • admin area 2 Haut-Rhin with place ID ChIJ919PNUx_kUcRwCk3mrlfCgM

  • admin area 1 Grand Est with place ID ChIJsbWPxd9VkUcR_RfRz30ZyLk

  1. 关于应用语言参数 language=hi,请注意,对于街道地址级别的结果,街道和地区的名称始终 return 以当地语言显示。此行为在以下博客 post
  2. 中进行了解释

https://maps-apis.googleblog.com/2014/11/localization-of-street-addresses-in.html

3.Regarding阿尔萨斯地区。请注意,地理编码服务 return 仅提供与地址格式相关的地址组件。在您的示例中,Alsace 不构成格式化地址 Rue Stanislas, 68000 Colmar, France 的一部分,因此在地址组件数组中被省略。

我可以看到 Google 数据库中的 Alsace 有一个类型 colloquial_area:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DAlsace%26options%3Dtrue%26country%3DFR

但是无法将其作为您在问题中提到的地址的地址组件。

希望我的回答能解决您的疑惑。