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

编程入门 行业动态 更新时间:2024-10-28 04:26:26
本文介绍了如何在 Windows Phone 8.1 通用应用程序中获取街道地址的地理位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 13:21:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地理位置   应用程序   街道   地址   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!