0

我的网站有问题;

我正在尝试将 microsoft bing 地图添加到我的 div 中,如下所示:

<body onload="getPosition();">
    <div id="panel">
            <div id="header">
                Some text here 
            </div>
            <div id="map" style="display:block; position:relative;"> 
            </div>
            <input type="button" name="loadForm">Load Form</input>
    </div>

加载地图的 Javascript 是这样完成的:

function getPosition() 
{
    var map;
    //get the map
    map = new Microsoft.Maps.Map(document.getElementById('map'), {credentials: bing_api, mapTypeId: Microsoft.Maps.MapTypeId.road, zoom: 1});
    if (navigator.geolocation)
    {
         //zoom into current location
         getCurrentLocation();
    }
    else
    {
        alert("Geolocation not supported");
    }
}

但是,我的地图永远不会加载,调试器告诉我错误Cannot call method 'appendChild' of null。看起来引发错误的代码来自 Microsoft。

我的问题是,我做错了吗?我的印象是,onload在 body 标记中执行该事件将确保在加载 body 的所有元素之前我不会创建标记(看来情况并非如此)。谢谢!

4

0 回答 0