如何在Google Maps API中指明语言?

Mat*_*att 33 javascript api google-maps google-maps-api-3

就像您访问maps.google.com.twmaps.google.co.krmaps.google.co.jp,您可以看到每个国家/地区都显示自己的语言.我可以在Google Maps API中使用任何属性来动态设置使用特定语言显示的Google地图吗?

Mak*_*nko 66

在Google Maps API v3中,为脚本标记添加"language"属性.例如,以下内容将设置map以在位置名称和导航按钮中显示俄语:

<script 
  src="http://maps.google.com/maps/api/js?sensor=false&amp;language=ru-RU"      
  type="text/javascript"></script> 
Run Code Online (Sandbox Code Playgroud)

结果:

替代文字

  • 在Javascript中加载地图后是否无法设置语言? (2认同)

小智 11

在Google Maps v3中,您可以使用"language"参数:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language=en"></script>
Run Code Online (Sandbox Code Playgroud)

语言代码列表:https://developers.google.com/maps/faq#languagesupport

更多信息:http://googlegeodevelopers.blogspot.com/2009/10/maps-api-v3-now-speaks-your-language.html


Dan*_*llo 7

对于V2 Maps API:

您可以在包含Google Maps API时hl<script>标记添加可选参数,并指定要使用的域语言,如以下示例所示:

<!DOCTYPE html>
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Localization of the Google Maps API</title> 
    <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&hl=ko"
            type="text/javascript"></script> 
  </head> 
  <body onunload="GUnload()"> 

    <div id="map_canvas" style="width: 400px; height: 300px"></div> 

    <script type="text/javascript"> 
       var map = new GMap2(document.getElementById("map_canvas"));
       map.setCenter(new GLatLng(36.48, 128.00), 7);
       map.setUIToDefault();
    </script> 
  </body> 
</html>
Run Code Online (Sandbox Code Playgroud)

截图:

Google Maps API的本地化

您可能还想查看以下资源以供进一步阅读: