如何使用LocationCollection缩放以适合WP7 Bing Maps控件? [英] How to zoom to fit in WP7 Bing Maps control using LocationCollection?

查看:72
本文介绍了如何使用LocationCollection缩放以适合WP7 Bing Maps控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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.Linqusing语句才能获取MinMax方法.

NOTE: You'll need a using statement for System.Linq to get the Min and Max methods.

这篇关于如何使用LocationCollection缩放以适合WP7 Bing Maps控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆