Google 地图 - 本地化
默认情况下,地图上给出的城市名称和选项名称将为英文。如果需要,我们也可以用其他语言显示此类信息。这个过程称为本地化。在本章中,我们将学习如何本地化地图。
本地化地图
您可以通过在 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>
输出
它将产生以下输出 -