分层的使用Google地方信息翻译placeId的结果 [英] Hierarchical & translated results of a placeId using Google Places

查看:90
本文介绍了分层的使用Google地方信息翻译placeId的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google地方信息搜索位置(也许我需要Google Maps才能实现自己的目标):

I'm using Google Places to search for a place (Maybe I need Google Maps in order to get my desired goal):

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 Places发送3个请求吗?并且在万一我必须这样做的情况下-如何在不使用id的情况下获得特定位置的精确结果(如果必须将text-searchHaut-Rhin一起使用,我也许可以获得更多结果)?

I have a few problems with this response: 1. I need the place ids for each: locality, administrative_area_level_2, administrative_area_level_1. In order to get them - do I have to send 3 more requests to google places ? And in case I have to - how can I get a precise result for a specific place without using id (If I have to use text-search with Haut-Rhin I can maybe get a few more results)?

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

  1. Even when sending language=hi I got only the country translated.

科尔马(Colmar)也属于Alsace地区,在任何地方都没有提及.

Colmar belongs also to Alsace region and it's not mentioned anywhere.

推荐答案

您的问题似乎有点笼统,但我会尽力解决您的疑问.

Your question seems to be a bit broad, but I'll try to address your doubts.

  1. 您说对了,响应中的地址组件当前未公开每个组件的位置ID,因此您必须执行其他请求才能获取地址组件的位置ID.

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

Please note that in Google issue tracker there is a feature request to add place ID of each address component in the response

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

随时为这个功能请求加注星标,以添加您的投票并订阅更多通知.

Feel free to star this feature request to add your vote and subscribe to further notifications.

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

In the meantime you can execute a reverse geocoding request for coordinates of your place to get place IDs of locality, admin area 1 and admin area 2. In your example the coordinate of the place is 48.0799554,7.3526162. Let's create reverse geocoding request to get information about locality and administrative areas:

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

此请求将返回

  • 具有地点ID ChIJz8Fw9t9lkUcRZulsYT5-XeM的本地科尔马

  • locality Colmar with place ID ChIJz8Fw9t9lkUcRZulsYT5-XeM

管理区2 Haut-Rhin,地点ID为ChIJ919PNUx_kUcRwCk3mrlfCgM

admin area 2 Haut-Rhin with place ID ChIJ919PNUx_kUcRwCk3mrlfCgM

管理区1 Grand Est,地点ID为ChIJsbWPxd9VkUcR_RfRz30ZyLk

admin area 1 Grand Est with place ID ChIJsbWPxd9VkUcR_RfRz30ZyLk

  1. 关于应用语言参数language=hi,请注意,对于街道地址级别结果,街道和地区名称始终以本地语言返回.以下博客文章对此行为进行了解释
  1. Regarding applying language parameters language=hi, please note that for street address level results the names of streets and localities are always returned in the local language. This behavior was explained in the following blog post

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

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

3.Regarding the Alsace region. Please note that geocoding service returns only address components relevant for the address formatting. In your example Alsace doesn't form part of the formatted address Rue Stanislas, 68000 Colmar, France, so it is omitted in the address components array.

我可以看到Google数据库中的阿尔萨斯类型为colloquial_area:

I can see that Alsace in Google database has a type colloquial_area:

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

但是,没有办法将其作为您在问题中提到的地址的地址组成部分.

However there is no way to get it as address component for the address that you mentioned in your question.

我希望我的回答能解决您的疑问.

I hope my answer addresses your doubts.

这篇关于分层的使用Google地方信息翻译placeId的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆