c# - 在 UWP 中获取 map 上元素的像素坐标

标签 c# xaml uwp windows-10 uwp-maps

所以我有一张 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/

相关文章:

c# - 无法激活 Windows 应用商店应用程序(Visual Studio 2015,Windows 10 版本 1511)

c# - 如何在 .net 属性上注入(inject)属性依赖项?

c# - 如何在 Telerik RadGrid 中选择行?

c# - 玩弄匿名类型

xaml - Windows Phone 8.1 上使用 MVVM Light 的双向数据绑定(bind)

xaml - Xamarin.Forms:无法解析程序集或 Windows 元数据文件 'Type universe cannot resolve assembly: MyApp.UI.Base...'

c# - 如何限制 foreach 循环 n 次运行?

wpf - 在 WPF/XAML 中创建 Alt 键快捷方式

c# - 'MouseEventArgs' 不包含 'GetPosition' 的定义

mvvm - 移动模拟器上的 Prism-Mvvm 应用程序部署错误