获取地图的视图边界

我正在开发一个适用于Bing Maps的Windows Phone 8.1应用程序。 在渲染此映射期间,我使用TrySetViewBoundsAsync来正确设置我的自定义视图。 但现在我想获取这些信息(在用户通过缩放/移动地图来更改视图之后),但我找不到任何有助于我的方法。

我怎样才能获得视图边界?

没有内置的方法,但它可以很容易地完成。 以下是我从Microsoft Maps Spatial Toolbox项目中提取的一些代码:

 public static GeoboundingBox GetBounds(this MapControl map) { Geopoint topLeft = null; try { map.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out topLeft); } catch { var topOfMap = new Geopoint(new BasicGeoposition() { Latitude = 85, Longitude = 0 }); Windows.Foundation.Point topPoint; map.GetOffsetFromLocation(topOfMap, out topPoint); map.GetLocationFromOffset(new Windows.Foundation.Point(0, topPoint.Y), out topLeft); } Geopoint bottomRight = null; try { map.GetLocationFromOffset(new Windows.Foundation.Point(map.ActualWidth, map.ActualHeight), out bottomRight); } catch { var bottomOfMap = new Geopoint(new BasicGeoposition() { Latitude = -85, Longitude = 0 }); Windows.Foundation.Point bottomPoint; map.GetOffsetFromLocation(bottomOfMap, out bottomPoint); map.GetLocationFromOffset(new Windows.Foundation.Point(0, bottomPoint.Y), out bottomRight); } if (topLeft != null && bottomRight != null) { return new GeoboundingBox(topLeft.Position, bottomRight.Position); } return null; } 

请注意, rbrundritt的解决方案不适用于倾斜(倾斜)视图。 在这种情况下,可见区域更类似于倒角梯形而不是边界框。 如果地平线可见,左上角可能也不是有效位置。

对于Windows 10周年更新(版本1607), MapControl支持新方法GetVisibleRegion()来帮助您。

以下应该返回地图的视图边界:

 map.GetVisibleRegion(MapVisibleRegionKind.Full) 

有关更多详细信息,请参阅MapControl文档。