Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

localization - Inconsistent language in Google Place Details API

I'm using Google Place Details API on my server to store information about a place, using the placeId sent by a client.

I'm facing an issue regarding the language of the result, which differs when the place is a city or an address in that city, even when the language is specified in the query. For example:

  • The place id ChIJ53USP0nBhkcRjQ50xhPN_zw is the city of Milan, and the API returns Milan as locality and Lombardy as administrative area (English names)

  • The place id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk is a street in Milan, and the API returns Milano as locality and Lombardia as administrative area (Italian names)

To make it even weirder, both searches return Italy as country. Is this the expected behavior of the API?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Is this the expected behavior of the API?

Yes, this is expected result. Even if you specify a language, it will return the response in that language only if there is one available, if not it will return the response in the language it was originally entered in.

Case 1:

  • Milan: As a Milan is city. Therefore,there are available results in almost every language. Almost all the major city through out the world have results in every language. By default, you will get result in English.

Case 2:

  • Via della Spiga: As it is a street. Right now, the results are only available in Italian as they were most possible entered in Italian.

Result when you search "Via della Spiga" in Google Map:

enter image description here

To learn more about this:

  1. Translation of Places information into language specified by request. In this a request for a feature is asked that tells the developer in which language the results are so that they can take care of data accordingly, I personally think that would be great till the issue has not been fixed.

  2. language parameter in place/details request not working

Both of the above issues are about 2 year old. Yet, Google is unable to resolve this issues.

One way to possibly solve this problem is by using textsearch:

As you can convert most of administrative area/city into any language name by using textsearch:

`https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&lang??uage=Your_language&key=YOUR_API_KEY` 

Example: Converting "Lombardia" into a chinese language:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&language=zh-CN&key=YOUR_API

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "意大利伦巴第",
         "geometry" : {
            "location" : {
               "lat" : 45.47906709999999,
               "lng" : 9.8452433
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 46.6351853,
                  "lng" : 11.4276993
               },
               "southwest" : {
                  "lat" : 44.6796491,
                  "lng" : 8.4978605
               }
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "02401d0909d69ca5c69de799e193caf84acc41f9",
         "name" : "伦巴第",
         "place_id" : "ChIJf4M-GsNEgUcR1JMVKCIm8qY",
         "reference" : "CoQBfQAAAEKCAV-1Ec-V2ZfnWsCk_elhlEXckc_k94jBYlU7k5ivhrqPlWd24aSAa5fqNTfwKKhU0wSsZFv42aMm1BrG5wEwZNGKwFqELxMEt0ye7KFfBgVtfHZbqeiBx3hEH8Iq60wwW--edqpROkBTjHrxIwisCGJwhCzKKkQ9H6FdfW_aEhAnmI0ZOFk1KGaGms4IqTOiGhRX5iErBIwnmLos4U9Ggs325MmcEA",
         "types" : [ "administrative_area_level_1", "political" ]
      }
   ],
   "status" : "OK"
}

Lombardia in chinese is 意大利伦巴第

When you search for placeID details, you get address_components array:

"address_components" : [
         {
            "long_name" : "Via della Spiga",
            "short_name" : "Via della Spiga",
            "types" : [ "route" ]
         },
         {
            "long_name" : "Milano",
            "short_name" : "Milano",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Milano",
            "short_name" : "MI",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "Lombardia",
            "short_name" : "Lombardia",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "Italy",
            "short_name" : "IT",
            "types" : [ "country", "political" ]
         }
      ]

So if you loop over the above array and use textsearch then you will get almost consistent address in a particular language.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...