问题
I am working on a bilingual project and started to use Google Places API Webservices. I started using the Place Autocomplete API which works great.
I can do this query in both fr
and en
and will get different description results:
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=
<insert_key_here>
&types=geocode&language=<insert_language_here>
&input=144
English result:
"description": "14458 Gouin Boulevard West, QC, Canada",
"id": "33dcffeeb88b48fa5c1d0ec4e6e54469d05f5d1e",
"place_id": "ChIJk0pAHBM7yUwRt0WIxWRe1ic",
French result:
"description": "14458 Boulevard Gouin Ouest, QC, Canada",
"id": "33dcffeeb88b48fa5c1d0ec4e6e54469d05f5d1e",
"place_id": "ChIJk0pAHBM7yUwRt0WIxWRe1ic",
The ids are exactly the same but the text is localized which is the expected result. Now when I try to get the same result using the Place Details API, the language parameter doesn't seem to have any impact. I know that the documentation mentions results should be returned, if possible.
but given I know it is possible, is this behavior by design or some sort of bug?
Here is an example of an english details query using the previous example place_id which returns the result in french:
https://maps.googleapis.com/maps/api/place/details/json?key=
<insert_key_here>
&placeid=ChIJk0pAHBM7yUwRt0WIxWRe1ic&language=en
"long_name": "Boulevard Gouin Ouest",
回答1:
While doing more researches, it looks like this is an old/known problem with the Google Places Details API. I did open a new issues here but given this has been reported multiple times there is no way to know when/if they will fix this.
An old 2012 thread can also be found with similar problems here.
Some workaround have been suggested in a previous stackoverflow post but for my given use case it did not do any good.
For the time being, the only real option I could think of would be to use Google Translate API which is unfortunately not free. Given the detail's response, one could parse every field and try to translate them before rebuilding an address. This would of course be a risky/fragile given that one cannot predict how the machine translation will work in all scenarios. Having Google support localization in their Places API would be much simpler option and make a lot of users happy.
来源:https://stackoverflow.com/questions/36228611/google-places-api-details-language-not-working