必应地图上多个图钉上的弹出信息框,可点击的图钉,但信息框未显示

问题描述 投票:0回答:1

我正在与此一起转圈。我正在尝试通过单击框旁边的单个信息框添加多个图钉。我可以显示图钉并使其可单击,但是信息框没有显示。

我要去哪里错了?

谢谢您的帮助!

下面的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=de-de" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=AhrgxvPMzaWNe4oDZqelNzT-SoWigBK7H8cSBqZ2jLXpq4O9IcQ1YktvHhqT7_8F' async defer></script> "

<div id="map" style="position: relative; width: 800px; height: 300px;"></div>


<script type="text/javascript">

function init(){

    // Initialize the map
    var map = new Microsoft.Maps.Map(
        document.getElementById("map"),
        {
            credentials: "My Bing Maps API Key",
            mapTypeId: Microsoft.Maps.MapTypeId.road
        }
    );


    var infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
        visible: false
    });

    infobox.setMap(map);

    // Create a collection to store multiple pins
    var pins = new Microsoft.Maps.EntityCollection();

    // Create pins
    for (var i = 0; i < 5; i++){

        var position = new Microsoft.Maps.Location(53 + i, -1);

        // Creates a Pushpin
        var pin = new Microsoft.Maps.Pushpin(position, {title: 'pin' + i} );
        pin.metadata = {
            title: 'Pin ' + i, 
            description: 'Description for pin ' + i
        };

        Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
        // Adds the pin to the collection instead of adding it directly to the Map
        pins.push(pin);
    }

    // Adds all pins at once
    map.entities.push(pins);
}

function pushpinClicked(e) {
        //Make sure the infobox has metadata to display.
        if (e.target.metadata) {
            //Set the infobox options with the metadata of the pushpin.
            infobox.setOptions({
                location: e.target.getLocation(),
                title: e.target.metadata.title,
                description: e.target.metadata.description,
                visible: true
            });
        }
    }
</script>


</body>
</html>
javascript html bing-maps
1个回答
0
投票

您在脚本标记中引用的Bing Maps V7。该版本几年前已过时。它在后台重定向到v8,但这不是100%向后兼容的,可能会引起问题。这是在V8上运行的同一示例:https://bingmapsv8samples.azurewebsites.net/#Infobox_MultiplePushpins

© www.soinside.com 2019 - 2024. All rights reserved.