Hierarchical & translated results of a placeId usi

2019-06-14 02:16发布

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

Response:

{
   "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"
}

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. Even when sending language=hi I got only the country translated.

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

1条回答
戒情不戒烟
2楼-- · 2019-06-14 02:34

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

  1. You are right the address components in the response currently doesn't expose a place ID of each component, so you have to execute additional request in order to get place IDs of address components.

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.

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

This request will return

  • locality Colmar with place ID ChIJz8Fw9t9lkUcRZulsYT5-XeM

  • admin area 2 Haut-Rhin with place ID ChIJ919PNUx_kUcRwCk3mrlfCgM

  • admin area 1 Grand Est with place ID ChIJsbWPxd9VkUcR_RfRz30ZyLk

enter image description here

  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.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.

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.

查看更多
登录 后发表回答