开发者

I want to add Map in innerHTML of Div(Dynamically created)

开发者 https://www.devze.com 2023-03-27 04:14 出处:网络
I want to add Map in innerHTML of Div(Dynamically created)..... var ni = document.getElementById(开发者_JAVA技巧\'content\');

I want to add Map in innerHTML of Div(Dynamically created).....

var ni = document.getElementById(开发者_JAVA技巧'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++;


There's a lot going on here that is wrong.

Lines 1-3,5. You've made #newdiv and appended it to your content div. Great!

Line 4: You're trying to set the contents of your new div with something that doesn't exist. Delete this line.

Line 6-11: Stock Google Maps code, straight from http://code.google.com/apis/maps/documentation/javascript/tutorial.html

Line 13: (unlucky for some) This line would handle the insertion of Google Maps to your page, if you changed the idname variable. How about trying this:

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

This will set up the Map object that you can use and put it in map[i]. Of course, I'm assuming you have a value for i and have initialised map. If not, then change map[i] = to var map =.

That should make your life easier :)

0

精彩评论

暂无评论...
验证码 换一张
取 消