在 Windows 通用应用程序中进行反向地理编码

本文关键字:编码 Windows 应用程序 | 更新日期: 2023-09-27 18:36:55

我有坐标,我正在尝试获取地址。 在Windows Phone 8 Silverlight应用程序中,我曾经使用ReverseGeocodeQuery来获取地址,但WinRT似乎不支持。

在 WinRT 中执行此操作的正确方法是什么,我应该使用类似的东西吗?

在 Windows 通用应用程序中进行反向地理编码

您可以使用

MapLocationFinder .这是我经常使用的代码片段。它基本上所做的是向MapLocationFinder发出查询并检查搜索是否成功。然后我选择第一个位置并检查是否设置了Town

当然,如果您愿意,您也可以对result.Locations进行检查并检查每个元素。

public static async Task<MapLocation> resolveLocationForGeopoint(Geopoint geopoint)
{
    MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(geopoint);
    if (result.Status == MapLocationFinderStatus.Success)
    {
        if (result.Locations.Count != 0)
            // Check if the result is really valid
            if (result.Locations[0].Address.Town != "")
                return result.Locations[0];
    }
    return null;
}