iframe中Bing地图中的多个位置

时间:2013-04-08 22:24:12

标签: javascript bing-maps referenceerror

我正试图让这段代码在iframe中运行,但我总是得到错误:

ReferenceError:未定义GetMap

我不是高级程序员,所以我不知道为什么它单独工作,而不是iframe(似乎没有人有同样的问题)!非常感谢帮助。

PS:编程代码主要来自YoYoMyo(谁在stackoverflow上发布),我只是根据我的用途进行了调整

    <html>
        <head>
            <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
            <script type="text/javascript" language="JavaScript">

            function GetMap() {
                var longitude = new Array();
                var latitude = new Array();
                var title = new Array();
                var description = new Array();


                longitude[0] = 47.5564154        //two defined locations
                latitude[0] = 7.59245395
                title[0] = "Basler Münster"
                description[0] = "Basel"

                longitude[1] = 47.55330556     //second defined Location
                latitude[1] = 7.59001851
                title[1] = "Theater Basel"
                description[1] = "Basel"

                var total = 2                //number of locations

                var pinInfoBox;  //the pop up info box
                var infoboxLayer = new Microsoft.Maps.EntityCollection();
                var pinLayer = new Microsoft.Maps.EntityCollection();
                var apiKey = "AmpgeSj6OVb9ILPwvjyIfwM3qmqm5yccyNGR_mxmbpw2znYZoXxQAz_KVbc84XCC";

                    map = new Microsoft.Maps.Map(document.getElementById("map"), {credentials: apiKey});

                    // Create the info box for the pushpin
                    pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false });
                    infoboxLayer.push(pinInfobox);


                    for (var i = 0 ; i < total; i++){
                        //add pushpins
                        var latLon = new Microsoft.Maps.Location(longitude[i], latitude[i]);
                        var pin = new Microsoft.Maps.Pushpin(latLon);
                        pin.Title = title[i];//usually title of the infobox
                        pin.Description = description[i]; //information you want to display in the infobox
                        pinLayer.push(pin); //add pushpin to pinLayer
                        Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
                    }

                    map.entities.push(pinLayer);
                    map.entities.push(infoboxLayer);
                    map.setView({zoom: 15, center: new Microsoft.Maps.Location(47.55330556, 7.59001851)});


                }

                function displayInfobox(e) 
                {
                    pinInfobox.setOptions({title: e.target.Title, description: e.target.Description, visible:true, offset: new Microsoft.Maps.Point(0,25)});
                    pinInfobox.setLocation(e.target.getLocation());
                }

                function hideInfobox(e) 
                {
                    pinInfobox.setOptions({ visible: false });
                }


            </script>

            <style>
                #map { position: relative; top: 0; left: 0; width: 100%; height: 800px; border:none;}
            </style>
        </head>
        <body onload="GetMap()">
            <div id="some stuff" style="width=100%; height:80px">
                some text
            </div>
            <div id="map" style="width=100%; height:800px">
            </div>
            <div id="some more stuff" style="width=100%; height:80px">
                some more text to read
            </div>              
        </body>
    </html> 

1 个答案:

答案 0 :(得分:0)

代码看起来很好,我无法重现您看到的错误。