必应地图 - 放大经度和经度数组



>我有两个 GPS 位置数组:lats[] 和 longs[]我使用这些数组将图钉放置到地图上。我想在放置图钉后放大图钉的区域。请帮助我编写代码来做到这一点。谢谢。

function LoadPushPins() 
 {
   var icon = new VECustomIconSpecification();
   for (var i = 0; i < lats.length; i++) 
    {
     var pp = new VEShape(VEShapeType.Pushpin, new VELatLong(lats[i],longs[i]));
     pp.SetDescription(theaddress[i]);
     pp.SetTitle(descs[i]);
     icon.Image = theicon[i];
     pp.SetCustomIcon(icon);
     map.AddShape(pp);
     }
   }

应提供了一种为图钉组实现最佳视图(位置和缩放)的方法。

var arrPushPinsLocations = [];
//Create array of locations using the longitude and latitude of yours pushpins.
arrPushPinsLocations.push(new Microsoft.Maps.Location(longitude, latitude));
//Create location rectangle object from arrPishPunsLocations and set the best view.  
map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(arrPushPinsLocations)});

一个例外,LocationRect必须至少包含两个位置点才能工作。解决方法是添加另一个正好靠近您真实位置的虚拟位置。例如:实际: (54.000000, 54.0000000)虚拟: (54.000001, 54.0000001)

我注意到您使用的是旧的 v6.3 版本的 Bing 地图。我强烈建议升级到功能更强大的必应地图 v7。这也是其他人的代码所基于的。如果您打算继续使用 v6.3(不推荐),您可以通过计算坐标数组的最佳中心和缩放级别,然后将其传递到地图的 SetCenterAndZoom 方法中来执行您想要的操作。这是一篇关于如何计算这些值的旧博客文章: http://rbrundritt.wordpress.com/2009/07/21/determining-best-map-view-for-an-array-of-locations/

请注意,v6.3 的文档甚至不再在线,将此作为对未来未来的提示。您可以在此处找到 v7 的迁移指南:http://social.technet.microsoft.com/wiki/contents/articles/20958.migrating-bing-maps-v6-3-to-v7.aspx

您可以使用 Bing Map 的 setView 方法。

您可以替换自己的纬度和经度值。

var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Map Credentials"}); 
map.setView({center:new Microsoft.Maps.Location(<latitude>, <longitude>), zoom: 9} );

最新更新