【问题标题】:Windows phone 8.1 get map corners geopointWindows phone 8.1 获取地图角落地理点
【发布时间】:2015-07-27 20:30:20
【问题描述】:

我试图找到角落的地理点

  • 左上角
  • 右上
  • 左下
  • 右下角

MapControl 提供的信息是

  • 中心(地理点)
  • ZoomLevel(双倍最小值:1,最大值:20)
  • 实际高度(双)
  • 实际宽度(双倍)

根据这些信息我能找到角吗?

我在想这样的事情:

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

这意味着Center Geopoint 位于HalfWdidth (X) 和HalfHeight (Y)。这对我有什么帮助吗?

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

【问题讨论】:

  • Get view bounds of a Map 的可能副本
  • @rbrundritt 感谢您提供该链接,它对我帮助很大,是的,它几乎是重复的 :)

标签: c# algorithm windows-phone-8.1 bing-maps geopoints


【解决方案1】:
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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多