如何使用LocationCollection缩放以适应WP7 Bing Maps控件?

Buj*_*uju 8 location zoom bing-maps windows-phone-7

如何在Windows Phone 7上将Microsoft.Phone.Controls.Maps.Map控件缩放到正确的缩放级别?

我有一个GeoCoordinates的LocationCollection,我自己计算了中心,但现在我如何计算正确的缩放级别以适应LocationCollection?

PS是否有开箱即用的方法来计算GeoCoordinates的中心,所以我不必自己计算?

编辑:我找到了另一个很好的解决方案:http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/

map.SetView(LocationRect.CreateLocationRect(points));

Der*_*kin 8

您可以使用以下代码计算LocationRect一组点的边界,然后将其传递LocationRectSetView()地图控件上的方法:

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);
Run Code Online (Sandbox Code Playgroud)

地图控件处理从当前位置到新位置的动画.

注意:您需要一个using声明System.Linq来获取MinMax方法.

  • 谢谢,我会接受你的回答,但我找到了另一个很好的解决方案:map.SetView(LocationRect.CreateLocationRect(points)); // http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/ (3认同)
  • 如果有人像我一样有点困惑,它在Windows Phone 8中称为LocationRectangle :) (2认同)