[英]Gmaps4rails - how to set map language
我想对Gmaps4rails生成的地图进行本地化,因此可以用用户所需的语言显示地名。 Google在此处记录了如何执行此操作: https : //developers.google.com/maps/documentation/javascript/examples/map-language
我使用的是Gmaps4rails的相当标准的(并且目前可以正常使用)实现,您可以在此处看到。
handler = Gmaps.build('Google');
handler.buildMap({
provider: { styles: mapStyle },
internal: {id: 'map'}
}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
正在渲染到html ...
<div class="map-container">
<div id="map"></div>
</div>
我只需要找出在哪里定义语言代码即可。 我尝试将它作为选项添加到提供程序中,没有任何乐趣(例如, provider: { styles: mapStyle, language: 'zh-TW' }
)。
我已经搜索了文档(和源代码),但是似乎找不到任何信息。 任何帮助,将不胜感激!
您必须在脚本中指出语言。
例如,在Maps API v3中现在说出您的语言 :
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=pt-BR">
您可以在此处找到语言列表。
这是代码示例:
<!DOCTYPE html>
<html>
<head>
<title>Localizing the Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example displays a map with the language and region set
// to Japan. These settings are specified in the HTML script element
// when loading the Google Maps JavaScript API.
// Setting the language shows the map in the language of your choice.
// Setting the region biases the geocoding results to that region.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: 35.717, lng: 139.731}
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&language=ja®ion=JP"
async defer>
</script>
</body>
</html>
如您在此代码行中看到的那样, key=YOUR_API_KEY&callback=initMap&
language=ja
®ion=JP
,语言设置为jp = Japanese 。
还要使用动态语言设置检查其工作示例 。
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.