1

我试图让这段代码在 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> 
4

1 回答 1

0

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

于 2013-11-29T22:51:22.393 回答