[英]Windows phone 8.1 get map corners geopoint
I trying to find the Geopoint of corners 我试图找到角落的Geopoint
The information that MapControl provides is MapControl提供的信息是
Based on that information can I find the corners? 根据这些信息,我可以找到角落吗?
I was thinking something like that: 我在想这样的事情:
double HalfHeight = Map.ActualHeight / 2;
double HalfWidth = Map.ActualWidth / 2;
So that means that Center
Geopoint is located on HalfWdidth
(X) and HalfHeight
(Y). 因此,这意味着Center
Geopoint位于HalfWdidth
(X)和HalfHeight
(Y)上。 Can somehow this help me? 能以某种方式对我有帮助吗?
Edit: My problem was very similar with this question as rbrundritt mentioned but it was giving only TopLeft and BottomRight. 编辑:我的问题与rbrundritt提到的这个问题非常相似,但它只给出了TopLeft和BottomRight。 Based on the accepted answer of that question (which is by rbrundritt) I also completed the other two and wrapped them in Extension, check my answer below. 基于该问题的公认答案(由rbrundritt提供),我还完成了另外两个问题并将它们包装在Extension中,请在下面检查我的答案。 Thank you 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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.