2012-02-12 48 views
0

因此,我想使用來自google的可視化地圖,並且希望顯示在我生成的JSP頁面上。 t正在Google AppEngine上託管。當我在Google App Engine上運行JSP時,這是生成的最終輸出。然而,在編譯之後,代碼看起來不錯,當我將它放入Google代碼操作區時,它可以工作,但在谷歌應用程序引擎中,它根本不起作用!這是發送到網頁的代碼。如何解決這個問題我完全喪失了。任何幫助將不勝感激。Google可視化在Google應用引擎的JSP中不顯示

謝謝! 喬恩

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>People</title> 
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=GOOGLEAPIKEYTHATISVALID" type="text/javascript"></script> 
<script type='text/javascript' src='https://www.google.com/jsapi'></script> 
<script language="text/javascript"> 
google.load('visualization', '1', {packages: ['geomap']}); 
function drawVisualization() { 
var data = new google.visualization.DataTable(); 
data.addRows(4); 
data.addColumn('string', 'State'); 
data.addColumn('number', 'Popularity'); 
data.setValue(0, 0, 'Pennsylvania'); 
data.setValue(0, 1, 10); 
data.setValue(1, 0, 'New York'); 
data.setValue(1, 1, 15); 
data.setValue(2, 0, 'California'); 
data.setValue(2, 1, 5); 
data.setValue(3, 0, 'New Jersey'); 
data.setValue(3, 1, 8); 


var options = {}; 
options['region'] = 'US'; 
var geomap = new google.visualization.GeoMap(
document.getElementById('container.page-wrap.mainContent.map_canvas')); 
geomap.draw(data, options); 
} 
</script> 
</head> 
<body > ##I have also done <body onload="drawVisualization()"> and that doesn't work either! 
<div id="container"> 
<div id="headerBar"> 
<P> this is a pretty header </p> 
</div> 
<div id="page-wrap"> 
<div id="mainContent"> 
<div id="map_canvas"></div>     
</div> 
</div> 
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> 
<div id="footer"> 
<P> This is the footer</P> 
<!-- end #footer --> 
</div> 
<!-- end #container --> 

</div> 
</body> 
</html> 

回答

1

有幾個問題:

  • <script>塊握着你的主要的Javascript內容包括以下屬性:language="text/javascript"。這應該是:type="text/javascript"
  • 的元素的參考應該是document.getElementById('map_canvas'));document.getElementById('container.page-wrap.mainContent.map_canvas'));
  • 我不知道你是怎麼打算的觸發drawVisualization,但考慮到這一點:google.setOnLoadCallback(drawVisualization);將呼籲負載的功能。

使用這些更改代碼將運行。希望有所幫助!