c# - Windows Phone 8.1 获取 map 角点geopoint

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

我试图找到角落的地理点

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

MapControl提供的信息是

  • 中心(地理点)
  • 缩放级别( double :1,最大值:20)
  • 实际高度(双人)
  • 实际宽度( double )

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

我是这么想的:

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

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

编辑: 我的问题与 this 非常相似问题为 rbrundritt提到但它只给出了 TopLeft 和 BottomRight。根据该问题的公认答案(由 rbrundritt 提供),我还完成了另外两个并将它们包装在扩展中,请在下面检查我的答案。谢谢你 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);
    }
}

关于c# - Windows Phone 8.1 获取 map 角点geopoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31662690/

相关文章:

c# - 使用授权属性时出现 NullReferenceException

c# - 如何使通用列表等于另一个通用列表

c# - 在 Windows 服务中使用 ocx 文件

algorithm - Tarjan 的算法 : Time Complexity and slight modification possibility

algorithm - 有没有办法划分rgb调色板?

c# - 从文件夹 RelativeID 获取文件夹 - Windows Phone

c# - 以编程方式更改 DockWindow 的宽度

python - 试图理解 python 递归函数

c# - 一段时间后摘要身份验证 token 无效

xaml - 2 列的 GridView,填充宽度