如何使用 LocationCollection 缩放以适应 WP7 Bing Maps 控件?
如何在 Windows Phone 7 上将 Microsoft.Phone.Controls.Maps.Map 控件缩放到正确的缩放级别?
我有一个地理坐标的 LocationCollection,并且我自己计算了中心,但现在如何计算正确的缩放级别以适合 LocationCollection?
PS 有没有一种开箱即用的方法来计算地理坐标的中心,这样我就不必自己计算它?
编辑: 我找到了另一个很好的解决方案: http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/
map.SetView(LocationRect .CreateLocationRect(points));
How can I zoom the Microsoft.Phone.Controls.Maps.Map control to the correct zoom level on Windows Phone 7?
I have a LocationCollection of GeoCoordinates and I calculated the Center myself, but now how do I calculate the correct zoom level to fit the LocationCollection?
P.S. Is there an out of the box method to calculate the center of GeoCoordinates so I don't have to calculate it myself?
EDIT:
I've found another fine solution: http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/
map.SetView(LocationRect.CreateLocationRect(points));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下代码计算包围一组点的
LocationRect
,然后将LocationRect
传递给SetView()
方法地图控件:地图控件处理从当前位置到新位置的动画。
注意:您需要使用
System.Linq
的using
语句来获取Min
和Max
方法。You can use the following code to calculate the
LocationRect
that bounds a set of points, and then pass theLocationRect
to theSetView()
method on the map control:The map control handles animating from the current position to the new location.
NOTE: You'll need a
using
statement forSystem.Linq
to get theMin
andMax
methods.德里克已经给出了答案,所以你应该接受他的答案,我为有很多点的情况提供了替代代码。这种方法仅迭代点集合一次而不是 4 次,但它在美观上并不令人愉悦。
Derek has already given the answer so you should accept his, I offer an alternative code for cases where there many points. This approach only iterates the points collection once instead 4 times however it isn't as asthetically pleasing.
正如其他答案所建议的,我将
SetView
与LocationRect
一起使用。然而我发现它总是产生低缩放级别,因为只使用整数值。例如,如果完美的缩放级别是 5.5,那么您将得到 5.0。为了获得合适的尺寸,我根据
TargetZoomLevel
和TargetBoundingRectangle
计算新的缩放级别:此示例将缩放级别设置为适合
viewRect
的高度屏幕。As suggested by the other answers I use
SetView
with aLocationRect
.However I found that it always produces to low zoom level, since only integer values was used. If for instance the perfect zoom level would be 5.5, you would get 5.0. To get a proper fit I calculate a new zoom level from
TargetZoomLevel
andTargetBoundingRectangle
:This example sets the zoom level to fit
viewRect
's height on the screen.