繁体   English   中英

Windows Phone 8.1获取地图角Geopoint

[英]Windows phone 8.1 get map corners geopoint

我试图找到角落的Geopoint

  • 左上方
  • 右上
  • 左下方
  • BottomRight

MapControl提供的信息是

  • 中心(Geopoint)
  • ZoomLevel(Double min:1,max:20)
  • 实际高度(双精度)
  • ActualWidth(双精度)

根据这些信息,我可以找到角落吗?

我在想这样的事情:

double HalfHeight = Map.ActualHeight / 2;
double HalfWidth = Map.ActualWidth / 2;

因此,这意味着Center Geopoint位于HalfWdidth (X)和HalfHeight (Y)上。 能以某种方式对我有帮助吗?

编辑:我的问题与rbrundritt提到的这个问题非常相似,但它只给出了TopLeft和BottomRight。 基于该问题的公认答案(由rbrundritt提供),我还完成了另外两个问题并将它们包装在Extension中,请在下面检查我的答案。 谢谢rbrundritt。

public static class MapExtensions
{
    private static Geopoint GetCorner(this MapControl Map, double x, double y, bool top)
    {
        Geopoint corner = null;

        try
        {
            Map.GetLocationFromOffset(new Point(x, y), out corner);
        }
        catch
        {
            Geopoint position = new Geopoint(new BasicGeoposition()
            {
                Latitude = top ? 85 : -85,
                Longitude = 0
            });

            Point point;
            Map.GetOffsetFromLocation(position, out point);
            Map.GetLocationFromOffset(new Point(0, point.Y), out corner);
        }

        return corner;
    }

    public static Geopoint GetTopLeftCorner(this MapControl Map)
    {
        return Map.GetCorner(0, 0, true);
    }

    public static Geopoint GetBottomLeftCorner(this MapControl Map)
    {
        return Map.GetCorner(0, Map.ActualHeight, false);
    }

    public static Geopoint GetTopRightCorner(this MapControl Map)
    {
        return Map.GetCorner(Map.ActualWidth, 0, true);
    }

    public static Geopoint GetBottomRightCorner(this MapControl Map)
    {
        return Map.GetCorner(Map.ActualWidth, Map.ActualHeight, false);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM