Bing映射图钉

时间:2014-07-09 14:38:32

标签: javascript bing-maps pushpin

我想绘制一张Bing地图,该地图采用纬度和经度值并在地图上绘制图钉。目前我只是使用一些测试数据,因为我刚开始学习API。下面的代码绘制了一个地图,但没有添加任何图钉。我似乎无法看到我所遗漏的内容,因此感谢任何反馈。

    <script>
        var getLocations = function(mapObj, latitude, longtitude)
        {
            for (var i = 0; i < latitude.length; i++)
            {
                var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(latitude[i] + ", " + longtitude[i]), null);
                Microsoft.Maps.Events.addHandler(pushpin, 'mouseup', ZoomIn);
                mapObj.entities.push(pushpin);
            }
        }

        var lats = [26.273714, 19.890723, 15.961329];
        var longs = [84.902344, 84.624022, 80.1416];

        var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
            credentials: 'myBingMapsKeyGoesHere'
        });

            map.entities.clear();
            getLocations(map, lats, longs);
            function ZoomIn(e) {
                if (e.targetType == 'pushpin') {
                    var location = e.target.getLocation();
                    map.setView({
                        zoom: 5,
                        center: location
                    });
                }
            }
     </script>

1 个答案:

答案 0 :(得分:1)

简单修复。问题在于如何为图钉创建位置对象。当你这样做时,你正在创建一个字符串:latitude [i] +&#34;,&#34; + longtitude [i]

而是这样做:new Microsoft.Maps.Location(latitude [i],longtitude [i]));