2010-04-18 23 views
30

就像你訪問maps.google.com.twmaps.google.co.krmaps.google.co.jp,你可以看到他們自己的語言顯示在每個國家。我可以在Google Maps API中使用哪些屬性來動態設置使用特定語言顯示的Google地圖?如何在Google Maps API中指定語言?

回答

60

在谷歌地圖API第3版,「語言」屬性添加到腳本標籤。例如,下面我們來設置地圖的地名和導航按鈕顯示俄羅斯:

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

結果:

alt text

+1

在JavaScript中加載地圖之後沒有辦法設置語言嗎? – Marc 2015-11-19 08:48:39

+0

仍然在尋找動態更改語言或API密鑰的方式。除手動腳本重新連接以外別無他法。 – Rantiev 2017-07-05 15:11:52

7

對於V2地圖API:

可以可選hl參數添加到包括谷歌地圖API時<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> 

截圖:

Localization of the Google Maps API

您可能還需要檢查以下資源進一步閱讀:

+0

感謝您的快速和準確的響應。 – Matt 2010-04-19 10:27:57

+1

我測試後,在v3中,語言「hl」參數尚不支持。 – Matt 2010-05-15 15:00:59