我有要获取地址的坐标。在 Windows Phone 8 Silverlight 应用程序中,我曾经使用 ReverseGeocodeQuery 来获取地址,但在 WinRT 中似乎不支持。
在 WinRT 中执行此操作的正确方法是什么,我应该使用类似的方法吗?
请您参考如下方法:
您可以使用 MapLocationFinder。这是我经常使用的代码片段。它基本上做的是向 MapLocationFinder 发出查询并检查搜索是否成功。然后我找到第一个位置并检查是否设置了 Town。
如果您愿意,您当然也可以在 result.Locations 上进行 foreach 并检查每个元素。
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;
}
