splash27
splash27

Reputation: 2107

How to use geocoding in Windows 8.1 App?

I need to get geocoordinates from address. I tried to go this way: http://www.braincastexception.com/wp7-web-services-first-part-geocodeservice/ but there are some errors.

1) Wrong argument:

GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

2) Event doesn't exist:

geocodeService.GeocodeCompleted += (sender, e) => geoCode_GeocodeCompleted(sender, e);

This article deals with Windows Phone 7, but i work with Windows 8.1 App. Maybe there is an another solution for Windows 8.1 App? What should I do?

Upvotes: 1

Views: 1420

Answers (2)

Kajzer
Kajzer

Reputation: 2385

To geocode do something like this:

async void GetLocation(string address, Geopoint queryHintPoint)
{
    var result = await MapLocationFinder.FindLocationsAsync(address, queryHintPoint);

    // Get the coordinates
    if(result.Status == MapLocationFinderStatus.Success)
    {
        double lat = result.Locations[0].Point.Position.Latitude;
        double lon = result.Locations[0].Point.Position.Longitude;
    }
}

And to reverse geocode:

async void GetLocationName(Geopoint yourLocation)
{
    var result = await MapLocationFinder.FindLocationsAtAsync(yourLocation);

    // Get the address
    if(result.Status == MapLocationFinderStatus.Success)
    {
        string address = result.Locations[0].Address.StreetNumber + result.Locations[0].Address.Street;
    }
}

Check out this article: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631249.aspx

It explains how to get locations in Windows Phone 8.1 maps.

Upvotes: 4

Related Questions