如何在 Windows Phone 8.1 通用应用程序中获取街道地址的地理位置? [英] How do I get Geolocation of a street address in Windows Phone 8.1 Universal App?

查看:30
本文介绍了如何在 Windows Phone 8.1 通用应用程序中获取街道地址的地理位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows Phone 用户将在文本字段中输入街道地址.我需要获取该地址字符串的地理位置,以便稍后计算该地理位置与手机当前地址的距离.

My windows phone user will be typing in a street address in a text field. I need to get the geolocation of that address string so I can later calculate distance of that geolocation and the phone's current address.

所以,我的问题是:
如何在 Windows Phone 8.1 通用应用中获取街道地址的地理位置?

我在 this stackoverflow answer 中找到了解决方案,但是,它适用于旧的 Silverlight 应用程序,而不是新的 Universal Store我目前使用的应用 API.

I found a solution in this stackoverflow answer, however, it's for the old Silverlight apps and not the new Universal Store app APIs that I'm currently using.

推荐答案

这里是获取地理位置和启动默认地图路线的代码

Here is the code to get geolocation and also to launch the default map for directions

这里是 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);
    }
}

这篇关于如何在 Windows Phone 8.1 通用应用程序中获取街道地址的地理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆