中心地图围绕 GeoPoints 以设置所有可见

Center map arround GeoPoints to set visible all them

我正在使用 MapControl 来显示一些 GeoPoints

XAML

<maps:MapControl x:Name="myMap">
...
</maps:MapControl>

C#

foreach (MapIcon icon in mapsIcons)
{
  myMap.MapElements.Add(icon);
}

我需要围绕地图中的所有 GeoPoint 自动(或以编程方式)居中和缩放地图,以便所有 MapIcon 都可见。有什么办法吗?

谢谢!

根据您的数据创建 BasicGeoposition 的列表或数组,然后将它们传递到 GeoboundingBox class:

var geoboundingBox = Windows.Devices.Geolocation.GeoboundingBox.tryCompute(positions);

然后将此边界框与地图的 TrySetViewBounds 一起使用:

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn637065.aspx

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn607971.aspx?cs-save-lang=1&cs-lang=javascript#code-snippet-1