bing 地图添加更多图钉

0 javascript maps bing-maps

我想在此地图中添加更多图钉。我尝试复制这部分:

\n\n
longitude[1] = 41.799645     //second defined Location\nlatitude[1] = 20.913514\ntitle[1] = "Kipper Market"\ndescription[1] = "Kipper Gostivar"\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我没有看到任何其他添加的引脚!有人可以帮忙吗?\n*我对java脚本几乎一无所知,所以如果我没有正确地提出我的问题,请不要评判我。\n谢谢!

\n\n

\n\n\n

\n\n
        function GetMap() {\n            var longitude = new Array();\n            var latitude = new Array();\n            var title = new Array();\n            var description = new Array();\n\n\n            longitude[0] = 42.0076215        //two defined locations\n            latitude[0] = 20.9689308\n            title[0] = "Kipper Market"\n            description[0] = "Braka Miladinovi 178, 1200 Tetov\xc3\xab, Tetovo, Macedonia"\n\n            longitude[1] = 41.799645     //second defined Location\n            latitude[1] = 20.913514\n            title[1] = "Kipper Market"\n            description[1] = "Kipper Gostivar"\n\n            var total = 0                //number of locations\n\n            var pinInfoBox;  //the pop up info box\n            var infoboxLayer = new Microsoft.Maps.EntityCollection();\n            var pinLayer = new Microsoft.Maps.EntityCollection();\n            var apiKey = "<api key>";\n\n            map = new Microsoft.Maps.Map(document.getElementById("map"), {credentials: apiKey});\n\n            // Create the info box for the pushpin\n            pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false });\n            infoboxLayer.push(pinInfobox);\n\n\n            for (var i = 0 ; i < 3; i++){\n                //add pushpins\n                var latLon = new Microsoft.Maps.Location(longitude[i], latitude[i]);\n                var pin = new Microsoft.Maps.Pushpin(latLon);\n\n                pin.Title = title[i];//usually title of the infobox\n                pin.Description = description[i]; //information you want to display in the infobox\n                pinLayer.push(pin); //add pushpin to pinLayer\n                Microsoft.Maps.Events.addHandler(pin, \'click\', displayInfobox);\n            }\n\n            map.entities.push(pinLayer);\n            map.entities.push(infoboxLayer);\n            map.setView({zoom: 10, center: new Microsoft.Maps.Location(41.9117244, 21.0254933)});\n\n\n        }\n\n        function displayInfobox(e) \n        {\n            pinInfobox.setOptions({title: e.target.Title, description: e.target.Description, visible:true, offset: new Microsoft.Maps.Point(0,25)});\n            pinInfobox.setLocation(e.target.getLocation());\n        }\n\n        function hideInfobox(e) \n        {\n            pinInfobox.setOptions({ visible: false });\n        }\n\n\n    </script>\n\n    <style>\n            #map { position: relative; top: 0; left: 0; width: 100%; height: 800px; border:none;}\n    </style>\n    </head>\n    <body onload="GetMap()">\n        <div id="some stuff" style="width=100%; height:80px">\n            some text\n        </div>\n        <div id="map" style="width=100%; height:400px">\n        </div>\n        <div id="some more stuff" style="width=100%; height:80px">\n            some more text\n        </div>              \n    </body>\n</html> \n
Run Code Online (Sandbox Code Playgroud)\n

Vad*_*hev 5

以下示例演示如何将多个图钉添加到 Bing 地图中:

\n\n

\r\n
\r\n
var pinInfobox;\r\n\r\nfunction GetMap() {\r\n\r\n    var pushpinInfos = [];\r\n    pushpinInfos[0] = { \'lat\': 42.0076215, \'lng\': 20.9689308, \'title\': \'Kipper Market\', \'description\': \'Braka Miladinovi 178, 1200 Tetov\xc3\xab, Tetovo, Macedonia\' };\r\n    pushpinInfos[1] = { \'lat\': 41.799645, \'lng\': 20.913514, \'title\': \'Kipper Market\', \'description\': \'Kipper Gostivar\' };\r\n\r\n    var infoboxLayer = new Microsoft.Maps.EntityCollection();\r\n    var pinLayer = new Microsoft.Maps.EntityCollection();\r\n    var apiKey = "<api key>";\r\n\r\n    var map = new Microsoft.Maps.Map(document.getElementById("map"), { credentials: apiKey });\r\n\r\n    // Create the info box for the pushpin\r\n    pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false });\r\n    infoboxLayer.push(pinInfobox);\r\n\r\n    var locs = [];\r\n    for (var i = 0 ; i < pushpinInfos.length; i++) {\r\n        locs[i] = new Microsoft.Maps.Location(pushpinInfos[i].lat, pushpinInfos[i].lng);\r\n        var pin = new Microsoft.Maps.Pushpin(locs[i]);\r\n        pin.Title = pushpinInfos[i].title;\r\n        pin.Description = pushpinInfos[i].description;\r\n        pinLayer.push(pin); \r\n        Microsoft.Maps.Events.addHandler(pin, \'click\', displayInfobox);\r\n    }\r\n\r\n    map.entities.push(pinLayer);\r\n    map.entities.push(infoboxLayer);\r\n\r\n    var bestview = Microsoft.Maps.LocationRect.fromLocations(locs);\r\n    map.setView({ center: bestview.center, zoom: 10 });\r\n}\r\n\r\nfunction displayInfobox(e) {\r\n    pinInfobox.setOptions({ title: e.target.Title, description: e.target.Description, visible: true, offset: new Microsoft.Maps.Point(0, 25) });\r\n    pinInfobox.setLocation(e.target.getLocation());\r\n}\r\n\r\nfunction hideInfobox(e) {\r\n    pinInfobox.setOptions({ visible: false });\r\n}
Run Code Online (Sandbox Code Playgroud)\r\n
<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0" type="text/javascript" charset="UTF-8"></script>\r\n<body onload="GetMap();">\r\n    <div id="map" style="position: relative; width: 600px; height: 450px;"></div>\r\n</body>
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n