Inconsistent language in Google Place Details API
Asked Answered
H

2

20

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?

Hyaloplasm answered 19/12, 2014 at 14:8 Comment(3)
Hi, would you mind sharing your code snippet where you are calling this API? I am getting troubles with this. My code does not return anything after calling this api.Unbelieving
Hi Nalin, it's a very simple request to the URL indicated in this documentation: developers.google.com/places/webservice/details , using cURL in PHP. If you have issues using it would probably be better to ask a new question.Hyaloplasm
Yes I am referring the same web page to do my stuff. I will ask a new question as soon as I go home. All that code is on my personal laptop.Unbelieving
H
13

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.

Heated answered 30/12, 2014 at 14:48 Comment(10)
In case 2, Milano is the city. This information is stored in the address components with 'locality' as type, just as is it in case 1... So Google knows the name of the city in both languages, there's no reason for the results to be inconsistent. But considering Google has known about this for two years, there isn't much to expect.Hyaloplasm
I meant to write "Via della Spiga" instead of "milano", Even if you search "milano" you will get place_id="ChIJ53USP0nBhkcRjQ50xhPN_zw" and will have result in most of the langauge(I mean textsearch). Basically what I meant was address for "Via della Spiga" was written in italian. if locality is only saved in one language then it will return in that language only but that is not the case with country. Right now I am searching an article that I have read long ago about how google save address. Will share with you?Heated
Sure. For now I'm considering using the city name given in case 2 with Autocomplete to get the city's placeId and reusing this placeId to get the name in english with Place Details. Kinda ugly but at least I'll get a consistent city name.Hyaloplasm
Although, it looks little messy but it will work. We can't do much about it as it's bug.Heated
You can just use textsearch setting language equal to english then you will get the english name of place in one call instead. I have checked it works for both "Milano" & "Lombardia". You can get both the results in english language by making one more call for each. https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&language=en&key=YOUR_API_KEYHeated
Using Textsearch indeed reduces the extra work to one API call, I didn't think of that one. Thanks a lot.Hyaloplasm
You are welcome :). Does it solve your problem? BTW which language you are using at server?Heated
I guess it's a solution although it forces another call to the API. I'm using english server-side.Hyaloplasm
Yeah, It increase the no of API call. There is one way to decrease the no. of api call i.e. use Geocoding on all the administrative area at once. https://maps.googleapis.com/maps/api/geocode/json?address=milano,lombardia,italy&language=hi&key=YOUR_API. link of jsFiddle with output. Now, you just need to make 2 API call and you are done because generally all the administrative area are available in all the language that google support. Hope it decreases your problem.Heated
There are good reasons behind the choice of language in all the above cases, see more details (and examples) at #33521186 ─ Places Autocomplete API is an exception to this: the terms returned will match what the user types in.Beethoven
B
0

I think you can use some Optional parameters to set what language you want, such that:

A Nearby Search request is an HTTP URL of the following form:

https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters

put language parameter, such that:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&language=en

For more detail, please refer here.

Bishop answered 19/12, 2014 at 23:7 Comment(1)
I already set the language parameter, the problem is the API ignores it for the city part of the address except when the placeId designates a city.Hyaloplasm

© 2022 - 2024 — McMap. All rights reserved.