Google Places API details language not working

懵懂的女人 提交于 2020-01-03 16:46:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!