如何使用LocationCollection缩放以适合WP7 Bing Maps控件? [英] How to zoom to fit in WP7 Bing Maps control using LocationCollection?
问题描述
如何在Windows Phone 7上将Microsoft.Phone.Controls.Maps.Map控件缩放到正确的缩放级别?
How can I zoom the Microsoft.Phone.Controls.Maps.Map control to the correct zoom level on Windows Phone 7?
我有一个GeoCoordinates的LocationCollection,我自己计算了中心,但是现在如何计算正确的缩放级别以适合LocationCollection?
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.是否有一种开箱即用的方法来计算GeoCoordinates的中心,所以我不必自己计算它?
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?
我找到了另一个不错的解决方案: http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/
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));
推荐答案
您可以使用以下代码来计算界定一组点的LocationRect
,然后将LocationRect
传递给SetView()
方法地图控件:
You can use the following code to calculate the LocationRect
that bounds a set of points, and then pass the LocationRect
to the SetView()
method on the map control:
var bounds = new LocationRect(
points.Max((p) => p.Latitude),
points.Min((p) => p.Longitude),
points.Min((p) => p.Latitude),
points.Max((p) => p.Longitude));
map.SetView(bounds);
地图控件处理从当前位置到新位置的动画.
The map control handles animating from the current position to the new location.
注意:您需要System.Linq
的using
语句才能获取Min
和Max
方法.
NOTE: You'll need a using
statement for System.Linq
to get the Min
and Max
methods.
这篇关于如何使用LocationCollection缩放以适合WP7 Bing Maps控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!