2013-05-15 115 views
2

我正在創建Google地理圖表,其中包含美國,韓國,臺灣,中國和印度的城市。如果我使用regions: 'world',那麼地圖將會太大,而城市的氣泡將幾乎不可見。我使用下列選項:在同一地圖中顯示多個谷歌地圖區域

var options = { 
    region: 'world', 
    displayMode: 'markers', 
    resolution: 'provinces' 
} 

是否有可能創建一個地圖兩個以上的區域?

例如,美國和亞洲。我在考慮設置使用類似以下內容的區域:

var options = { 
    region: '019','142', 
    displayMode: 'markers', 
    resolution: 'provinces' 
} 

回答

1

不,不可能在同一個地圖上創建兩個區域的地圖。

原因是Google geocharts依賴於他們展示的任何區域的SVG圖像,並且API中存在有限數量的SVG地圖(這就是爲什麼有些國家不能使用resolution: 'provinces')。

但是,可以爲兩個區域創建包含數據的數據表,並使用相同的數據表來填充兩個單獨的地圖(每個區域之一)。

例如:

<!-- 
You are free to copy and use this sample in accordance with the terms of the 
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html) 
--> 

<!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: ['geochart']}); 

     function drawVisualization() { 
     var data = google.visualization.arrayToDataTable([ 
      ['Country', 'Popularity'], 
      ['Germany', 200], 
      ['United States', 300], 
      ['Brazil', 400], 
      ['Canada', 500], 
      ['France', 600], 
      ['RU', 700] 
     ]); 

     // Draw First Chart 
     var geochart = new google.visualization.GeoChart(
      document.getElementById('visualization')); 
     geochart.draw(data, {width: 556, height: 347, region: '019', resolution: 'countries'}); 

     // Draw Second Chart 
     var geochart2 = new google.visualization.GeoChart(
      document.getElementById('visualization2')); 
     geochart2.draw(data, {width: 556, height: 347, region: '150', resolution: 'countries'}); 
     } 


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

還要注意的是,「美洲」區域(019)是世界地圖一樣高,並且不會將任何空間裏,真正爲您節省了「世界」。如果在加拿大或墨西哥沒有任何標記,我會建議使用北美或「美國」。