How do I get Geolocation of a street address in Windows Phone 8.1 Universal App?

放肆的年华 提交于 2019-12-23 17:06:03

问题


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.

So, my question is:
How do I get Geolocation of a street address in Windows Phone 8.1 Universal App?

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.


回答1:


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

Here is MSDN link

    // 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);
    }
}


来源:https://stackoverflow.com/questions/23728074/how-do-i-get-geolocation-of-a-street-address-in-windows-phone-8-1-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!