gpt4 book ai didi

javascript - iframe 中 Bing map 中的多个位置

转载 作者:行者123 更新时间:2023-11-28 09:14:07 24 4
gpt4 key购买 nike

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

最佳答案

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

关于javascript - iframe 中 Bing map 中的多个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com