2010-08-16 68 views
4

我有以下的世界地圖:的javascript:谷歌地球 - 地圖

<!-- 
    copyright (c) 2009 Google inc. 

    You are free to copy and use this sample. 
    License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license 
--> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>Google Visualization API Sample</title> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
    google.load('visualization', '1', {packages: ['geomap']}); 

    function drawVisualization() { 
     var data = new google.visualization.DataTable(); 
     data.addRows(6); 
     data.addColumn('string', 'Country'); 
     data.addColumn('number', 'Popularity'); 
     data.setValue(0, 0, 'Germany'); 
     data.setValue(0, 1, 200); 
     data.setValue(1, 0, 'United States'); 
     data.setValue(1, 1, 300); 
     data.setValue(2, 0, 'Brazil'); 
     data.setValue(2, 1, 400); 
     data.setValue(3, 0, 'Canada'); 
     data.setValue(3, 1, 500); 
     data.setValue(4, 0, 'France'); 
     data.setValue(4, 1, 600); 
     data.setValue(5, 0, 'RU'); 
     data.setValue(5, 1, 700); 

     var geomap = new google.visualization.GeoMap(
      document.getElementById('visualization')); 
     geomap.draw(data, null); 
    } 


    google.setOnLoadCallback(drawVisualization); 
    </script> 
</head> 
<body style="font-family: Arial;border: 0 none;"> 
<div id="visualization" style="width: 800px; height: 400px;"></div> 
</body> 
</html> 

而不是顯示地圖整個世界的我想知道如何顯示只是美國?

回答

2

從你的榜樣,在地理分佈圖設置region option

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>Google Visualization API Sample</title> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
    google.load('visualization', '1', {packages: ['geomap']}); 

    function drawVisualization() { 
     var data = new google.visualization.DataTable(); 
     data.addRows(6); 
     data.addColumn('string', 'Country'); 
     data.addColumn('number', 'Popularity'); 
     data.setValue(1, 0, 'United States'); 
     data.setValue(1, 1, 300); 

     var geomap = new google.visualization.GeoMap(
      document.getElementById('visualization')); 

     var options = { region: 'us_metro' }; 
     geomap.draw(data, options); 
    } 


    google.setOnLoadCallback(drawVisualization); 
    </script> 
</head> 
<body style="font-family: Arial;border: 0 none;"> 
<div id="visualization" style="width: 800px; height: 400px;"></div> 
</body> 
</html> 

不明白爲什麼要設置其他國家的普及,只是在美國,雖然中心。

+0

jack我在哪裏可以找到這個教程?我不想要任何其他國家,除了美國和其他國家 – 2010-08-16 17:03:48

+0

然後只使用區域:'us_metro',在您提供的代碼中替換geomap.draw(data,null);用我給你的兩條線。 – 2010-08-16 17:52:37

+0

,這給了我所有的縣,我的意思是我只想要州,我該怎麼做? – 2010-08-17 15:13:45