Google Maps教程

Google Maps 本地化

默认情况下,地图上给出的城市名称和选项名称将为英文。如果需要,我们也可以以其他语言显示此类信息。此过程称为 本地化。在本章中,我们将学习如何定位地图。

定位地图

您可以通过在 URL 中指定语言选项来自定义(本地化)地图的语言,如下所示。
<script src = "https://maps.googleapis.com/maps/api/js?language=zh-Hans"></script>

示例

以下示例展示了如何本地化 GoogleMaps。在这里,您可以看到本地化为中文的中国路线图。
<!DOCTYPE html>
<html>
   <head>
      <script src = "https://maps.googleapis.com/maps/api/js?language=zh-Hans"></script>
      
      <script>
         function loadMap() {
			
            var mapOptions = {
               center:new google.maps.LatLng(32.870360, 101.645508),
               zoom:9, 
               mapTypeId:google.maps.MapTypeId.ROADMAP
            };
				
            var map = new google.maps.Map(document.getElementById("sample"),mapOptions);
         }
      </script>
      
   </head>
   
   <body onload = "loadMap()">
      <div id = "sample" style = "width:580px; height:400px;"></div>
   </body>
</html>
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4