简体   繁体   English

Javascript OpenLayers:Google图层与语言的行为

[英]Javascript OpenLayers: Google layer behavior with languages

I'm having problem with City names on the google layer. 我在Google图层上的城市名称有问题。 Depending on browser language it's automatically pick the names of Cities on this language. 根据浏览器语言,它会自动选择使用该语言的城市名称。

I have tried language setting here: http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Lang-js.html#OpenLayers.Lang.setCode 我在这里尝试过语言设置: http : //dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Lang-js.html#OpenLayers.Lang.setCode

But have no effect. 但是没有效果。 Maybe i'm doing it wrong? 也许我做错了吗? How to apply this setting on current map object? 如何在当前地图对象上应用此设置?

For example if language is english town name will be Riga, but if russian, then Рига. 例如,如果语言为英语,城镇名称将为里加,但如果为俄语,则为Рига。 Is it possible somehow to turn this behavior off or force english only map, because when i set markers on one map, it looks different on another. 是否有可能以某种方式关闭此行为或强制使用仅英语地图,因为当我在一张地图上设置标记时,在另一张地图上看起来有所不同。

Resulting marker overlapping text and so on. 结果标记重叠文本,依此类推。

Thanks. 谢谢。

Here's the answer from documentation: 这是文档中的答案:

The Google Maps API uses the browser's preferred language setting when displaying textual information such as the names for controls, copyright notices, driving directions and labels on maps. 在显示文字信息(例如控件名称,版权声明,行车路线和地图上的标签)时,Google Maps API使用浏览器的首选语言设置。 In most cases, this is preferable; 在大多数情况下,这是可取的。 you usually do not wish to override the user's preferred language setting. 您通常不希望覆盖用户的首选语言设置。 However, if you wish to change the Maps API to ignore the browser's language setting and force it to display information in a particular language, you can add an optional language parameter to the tag when including the Maps API javascript code, specifying the language to use. 但是,如果您希望更改Maps API以忽略浏览器的语言设置并强制其以特定语言显示信息,则可以在添加Maps API javascript代码时在代码中添加可选的language参数,以指定要使用的语言。 For example, to display a Maps API application in Japanese, add &language=ja to the 例如,要以日语显示Maps API应用程序,请将&language = ja添加到

<script>

tag as shown below: 标签,如下所示:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=ja">

Note: loading the API in the manner shown above will use the Japanese language for all users regardless of user preferences. 注意:以上述方式加载API将对所有用户使用日语,而不考虑用户的偏好。 Be sure you wish this behavior before setting this option. 在设置此选项之前,请确保您希望这种行为。

So in your case you should add language=en parameter when you load google maps api. 因此,在您的情况下,您在加载google maps api时应添加language = en参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM