所以我有一张 map 。在它上面我有一些按地理位置定位的 XAML 元素。我需要找到它们的像素坐标,以便检测它们何时相互重叠(用于分组目的) 我似乎找不到办法。如果我得到 MyMap.MapItems ,我只会得到绑定(bind)到 map 的对象的集合。 有什么想法如何做到吗?
最佳答案
好问题。我目前有这样的问题。这是一篇文章,准确描述了您需要做什么。 https://msdn.microsoft.com/en-us/library/bb259689.aspx?f=255&MSPPError=-2147217396
如果您没有时间阅读代码:
private const double EarthRadius = 6378137;
private const double MinLatitude = -85.05112878;
private const double MaxLatitude = 85.05112878;
private const double MinLongitude = -180;
private const double MaxLongitude = 180;
private static double Clip(double n, double minValue, double maxValue)
{
return Math.Min(Math.Max(n, minValue), maxValue);
}
public static uint MapSize(int levelOfDetail)
{
return (uint) 256 << levelOfDetail;
}
public static void LatLongToPixelXY(double latitude, double longitude, int levelOfDetail, out int pixelX, out int pixelY)
{
latitude = Clip(latitude, MinLatitude, MaxLatitude);
longitude = Clip(longitude, MinLongitude, MaxLongitude);
double x = (longitude + 180) / 360;
double sinLatitude = Math.Sin(latitude * Math.PI / 180);
double y = 0.5 - Math.Log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
uint mapSize = MapSize(levelOfDetail);
pixelX = (int) Clip(x * mapSize + 0.5, 0, mapSize - 1);
pixelY = (int) Clip(y * mapSize + 0.5, 0, mapSize - 1);
}
关于c# - 在 UWP 中获取 map 上元素的像素坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39160164/