将多个图钉添加到绑定映射

时间:2018-09-30 22:17:57

标签: javascript html5

下面的脚本显示了bing地图,上面有我的当前位置图钉。

 <script>
    var map;
    function loadMapScenario() {
                map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
    }

    function loadMapScenario() {
            var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
            var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null);
            map.entities.push(pushpin);

        }
    </script>
</head>
<body onload='loadMapScenario();'>
    <div id='printoutPanel'></div>
    <div id='myMap' style='width: 100vw; height: 100vh;'></div>
</body>

我有一系列经度和纬度类似的位置:

     var listRecs =[  
       {  
          "name":"Carlisle Community Centre & Arena",
          "address":"1496 Centre Road",
          "city":"Carlisle",
          "phone":"905-689-7283",
          "latitude":"43.39606",
          "longtitude":"-79.98293"
       },
       {  
          "name":"Chedoke Twin Pad Arena",
          "address":"91 Chedmac Dr.",
          "city":"Hamilton",
          "phone":"905-546-2429",
          "latitude":"43.23889",
          "longtitude":"-79.92077"
       },

我试图制作一个for循环,使用他们的图钉将上述位置放到tocthe bing地图中,但这似乎不起作用

   for(var i = 0; i < listRecs.length; i++){

        location[i] = new Microsoft.Maps.Location(listRecs[i].latitude,listRecs[i].longtitude);
        var pushpin = new Microsoft.Maps.PushPin(location[i]);
         map.entities.push(pushpin);
         }

0 个答案:

没有答案