Google地图API V3响应语言对于城市名称是错误的 [英] Google maps API V3 response language is wrong for city name

查看:147
本文介绍了Google地图API V3响应语言对于城市名称是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施Google地图API。除了谷歌的回应之外,所有的工作都很好。该响应将城市名称翻译为我的语言环境语言(NL),但以所需语言(EN)离开该国家。



地图和自动填充都显示EN名称的城市。然而,当点击一个建议时,输入获得的变化只需几分之一秒到达NL变体(再次在EN中留下国家名称)



这里是我正在使用的脚本标记: b
$ b

 < script type =text / javascriptsrc =' http://maps.google.com/maps/api/js?libraries=places&language=en&key=MYKEY'></script> 

我得到的当前输出:

  addressLine1:14 Bisschopsstraat
addressLine2:
city:Brussel
国家:比利时
country_short:BE
postalCode:1000
stateOrProvince:Brussel
streetName:Bisschopsstraat
streetNumber:14

我试过了:


  • region = GB 添加到脚本标记src查询中,但这只会影响搜索区域的优先级

  • 全部读取文档(关于如何更改响应的语言并没有太多)



什么是错误的例子与回应:


Brussel 应该是布鲁塞尔



Antwerpen 应该是安特卫普


解决方案

如果您使用地理编码或地点服务,这似乎是预期的行为。

请看看这篇文章:
http://googlegeodevelopers.blogspot.com.es/2014/11/localization-of-street-addresses-in.html


Google地图地理编码API返回的街道级地址现在支持本地语言,同时尽可能地保持地址的可理解性,只读取请求的语言以及当地人。



如果本地语言和用户语言都使用相同的字母表,则Geocoding API现在将返回街道的本地名称和地方。例如,在用户语言设置为英语的巴西搜索地址现在返回Avenida Paulista而不是Paulista Avenue。

我可以考虑的解决方法如下:


  1. 您从自动完成元素
    获得地点ID https:// maps。 googleapis.com/maps/api/place/autocomplete/json?input=Bisschopsstraat%2014%2C%20Brussels%2C%20Belgium&key=YOUR_API_KEY
    返回地点ID EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt

  2. 您执行地点详情请求以获取经度和纬度
    https://maps.googleapis.com/maps/api/place/details/jso n?placeid = EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt& key = YOUR_API_KEY 这将返回50.8503548,4.351704499999999
  3. 执行经度,纬度的反向地理编码,指定结果类型为英语的地点和语言
    https ://maps.googleapis.com/maps/api/geocode/json?latlng = 50.8503548%2C4.351704499999999& language = en& result_type = locality& key = YOUR_API_KEY 此处您有 formatted_address:比利时布鲁塞尔


I am trying to implement the google maps API. All is working well except for the response which is coming back from google. The response translates the city name to my locale language (NL) but leaves the country in the desired language (EN).

Both the map and the autocomplete are displaying EN names of cities. However when clicking on a suggestion the input get's changed in just a fraction of a second to the NL variant (again leaving the country name in EN)

Here is the script tag that I am currently using:

<script type="text/javascript" src='http://maps.google.com/maps/api/js?libraries=places&language=en&key=MYKEY'></script>

The current output I get:

addressLine1:"14 Bisschopsstraat"
addressLine2:""
city:"Brussel"
country:"Belgium"
country_short:"BE"
postalCode:"1000"
stateOrProvince:"Brussel"
streetName:"Bisschopsstraat"
streetNumber:"14"

I have tried:

  • Adding a region=GB to the script tag src query but that just influences the search area priorities
  • Reading all the documentation (there is not that much on how to change the language of the response though)

Examples of what is wrong with the response:

Brussel should be Brussels

Antwerpen should be Antwerp

解决方案

If you use geocoding or places service this seems to be the intended behavior.

Please have a look at this post: http://googlegeodevelopers.blogspot.com.es/2014/11/localization-of-street-addresses-in.html

Street-level addresses returned by the Google Maps Geocoding API now favor the local language, while keeping the address understandable as much as possible for both a user who only reads the requested language as well as locals.

If the local language and user language both use the same alphabet, the Geocoding API will now return the local names for the streets and localities. For example, searching for an address in Brazil with user language set to English now returns "Avenida Paulista" rather than "Paulista Avenue".

The workaround I can think about is the following:

  1. You get a place ID from autocomplete element https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Bisschopsstraat%2014%2C%20Brussels%2C%20Belgium&key=YOUR_API_KEY This returns place ID EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt
  2. You execute place details request to get latitude and longitude https://maps.googleapis.com/maps/api/place/details/json?placeid=EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt&key=YOUR_API_KEY This will return 50.8503548,4.351704499999999
  3. Execute reverse geocoding for latitude,longitude specifying result type as locality and language as English https://maps.googleapis.com/maps/api/geocode/json?latlng=50.8503548%2C4.351704499999999&language=en&result_type=locality&key=YOUR_API_KEY And here you have "formatted_address":"Brussels, Belgium"

这篇关于Google地图API V3响应语言对于城市名称是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆