如何在Windows Phone 8.1通用应用程序中获得街道地址的地理位置?

本文关键字:街道 地址 地理位置 应用程序 Windows Phone 1通 | 更新日期: 2023-09-27 18:04:01

我的windows phone用户将在文本字段中键入街道地址。我需要得到那个地址字符串的地理位置,这样我就可以计算那个地理位置和手机当前地址的距离。

我的问题是:
如何在Windows Phone 8.1通用应用程序中获得街道地址的地理位置?

我在这个stackoverflow答案中找到了一个解决方案,然而,它适用于旧的Silverlight应用程序,而不是我目前使用的新的通用商店应用程序api。

如何在Windows Phone 8.1通用应用程序中获得街道地址的地理位置?

下面是获取地理位置和启动默认地图的代码

这是MSDN链接

    // Nearby location to use as a query hint.
BasicGeoposition queryHint = new BasicGeoposition();
    // DALLAS
queryHint.Latitude = 32.7758;
queryHint.Longitude = -96.7967;
Geopoint hintPoint = new Geopoint(queryHint);
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(
                        "street, city, state zip",
                        hintPoint,
                        3);
if (result.Status == MapLocationFinderStatus.Success)
{
    if (result.Locations != null && result.Locations.Count > 0)
    {
        Uri uri = new Uri("ms-drive-to:?destination.latitude=" + result.Locations[0].Point.Position.Latitude.ToString() +
            "&destination.longitude=" + result.Locations[0].Point.Position.Longitude.ToString() + "&destination.name=" + "myhome");
        var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    }
}