Windows phone 8.1获取地图角的地理点
本文关键字:地图 phone 获取 Windows | 更新日期: 2023-09-27 18:04:53
我试图找到角的地理点
- TopLeft
- TopRight
- BottomLeft
- BottomRight
MapControl提供的信息是
- 中心(Geopoint)
- ZoomLevel (Double min:1, max:20)
- ActualHeight (Double)
- ActualWidth (Double)
根据这些信息我能找到拐角吗?
我是这么想的:
double HalfHeight = Map.ActualHeight / 2;
double HalfWidth = Map.ActualWidth / 2;
这意味着Center
地理点位于HalfWdidth
(X)和HalfHeight
(Y)上,这对我有帮助吗?
编辑:我的问题与rbrundritt提到的这个问题非常相似,但它只给出了topleleft和BottomRight。基于该问题的公认答案(这是由rbrundritt),我还完成了其他两个问题,并将它们包装在Extension中,请查看下面的答案。谢谢你brundritt。
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);
}
}