2011-08-09 25 views
0

我想添加地圖在事業部(動態創建的)的innerHTML的innerHTML的的.....我想添加地圖在事業部(動態創建的)

var ni = document.getElementById('content'); 
var newdiv = document.createElement('div'); 
newdiv.setAttribute('id',idname); 
newdiv.innerHTML = map[i];//it is not adding map,because map[i] is not defined...how to solve this... 
ni.appendChild(newdiv); 
var latlng = new google.maps.LatLng(-34.397, 150.644); 
var myOptions = { 
    zoom: 8, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

map[i] = new google.maps.Map(document.getElementById(idname),myOptions); 
i++; 

回答

0

有很多怎麼回事,這是錯誤。

第1-3,5行。您製作了#newdiv並將其附加到您的內容分區。大!

第4行:您試圖用不存在的東西設置新div的內容。 刪除此行。

線6-11:股票谷歌地圖代碼,直接從http://code.google.com/apis/maps/documentation/javascript/tutorial.html

13號線:(不吉利的一些)這條線將處理谷歌地圖插入到你的頁面,如果你改變了與idName變量。試試這個如何:

map[i] = new google.maps.Map(ni, myOptions); 

這將設置您可以使用的地圖對象,並將其放置在地圖[i]中。當然,我假設你的價值爲i,並已初始化爲map。如果不是,則將map[i] =更改爲var map =

這應該會讓你的生活更輕鬆:)

相關問題