簡體   English   中英

在iframe中的必應地圖中有多個位置

[英]Multiple Locations in Bing Maps in an iframe

我正在嘗試讓這段代碼在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> 

該代碼看起來不錯,我無法重現您看到的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM