我正在使用全新的 Windows Phone 8 map 控件,但遇到了一个问题:我需要获取 map 边界的 LocationRectangle,即纬度跨度和经度跨度。
使用 Bing map 控件,您可以:
LocationRect bounds = map.Bounds;
...但是,这个新控件中似乎没有相关字段。谁能帮忙,或者我是否需要对各种缩放级别进行逆向工程并根据中心点、缩放级别和像素高度/宽度计算出来?
最佳答案
您可以使用视口(viewport)转换方法,例如:
GeoCoordinate topLeft = yourMapInstance.ConvertViewportPointToGeoCoordinate(new Point(0, 0));
GeoCoordinate bottomRight =
yourMapInstance.ConvertViewportPointToGeoCoordinate(new Point(mapSize.Width, mapSize.Height));
return LocationRectangle.CreateBoundingRectangle(new[] { topLeft, bottomRight });
也许您可以直接使用 mapControl 实例的 renderSize,但为了确保运行时的正确尺寸,我建议监听“SizeChanged”事件。检查 mapsize 值不为 0 或 Infinite 可能也是一个好主意。
关于c# - Windows Phone 8 map 控件 - 如何获取 map 边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13184388/