javascript - Google map 自动填充中的城市不是英文的

标签 javascript google-maps google-maps-api-3

  1. 我在连接 Google Maps API 时使用参数 language=en

  2. 我使用此代码来检测城市:

    function locationHelper(array, key) {
        var location = false;
    
        $.each(array, function (i, object) {
            if (object.types[0] == key) {
                location = (object.long_name != "") ? object.long_name : object.short_name;
            }
        });
    
        return location;
    }  
    
           autocomplete.addListener('place_changed', function() {
                var place = autocomplete.getPlace();
                var city = locationHelper(place.address_components, 'locality');
                console.log(city);
            });
    

enter image description here

当我显示来自 autocomplete.getPlace() 的数据时,为什么 Google 会向我发送罗马尼亚语变体 (Bucureşti) 的布加勒斯特?

<小时/>

来自文档:

默认占位符文本会自动本地化。如果您指定自己的占位符值,则必须在应用程序中处理该值的本地化。有关 Google Maps JavaScript API 如何选择要使用的语言的信息,请阅读有关本地化的文档。

<小时/>

我一开始就这么做了。正如我们所看到的,Google 建议我们为变体选择一种语言。仅针对变体,没有关于结果的消息。我还没有找到任何解决方案。

最佳答案

详细地址格式遵循 Google 在以下文档中描述的政策:

https://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.

这同样适用于 Places API 详细信息,但是,自动完成功能似乎不遵循此准则,但我相信 Google 目前正在研究此问题。

关于javascript - Google map 自动填充中的城市不是英文的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40347630/

相关文章:

javascript - sencha touch 同步存储性能问题

java.lang.RuntimeException : Waited too long for browser bridge with googlemaps

java - 如何为 Google map 设置特定中心?

javascript - 加载 OpenLayers 库及其依赖项(Google 和 OSM)是否可能异步?

javascript - 当用户点击链接时插入 MySQL 数据库

javascript - 传单 - 瓷砖加载事件

javascript - 使用javascript获取相对URL

javascript - AngularJS 在指令中操作父级的 DOM

objective-c - 使用 google maps api v3 更改 iOS 中的位置权限对话框

javascript - Google Maps API,添加标记是否会影响使用限制?