RichC
RichC

Reputation: 7879

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

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.

Upvotes: 3

Views: 3274

Answers (1)

Prashan Pratap
Prashan Pratap

Reputation: 484

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

Upvotes: 3

Related Questions