gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:21:07 24 4
gpt4 key购买 nike

我试图找到角落的地理点

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com