civic address in wp8

1

I am working on a wp8 project and need to find the location . I've used windows.device.geoloaction name space to find the lattitude and longitude now I need to find the address(country state and zip). I found this example but I am confused how to pass the coordinates that I obtained . Here is my code.

public async void FindTADeviceLocation()
{
    ////Declare  Geolocator object
    Geolocator geolocator = new Geolocator();

    //  Set user's accuracy 
    geolocator.DesiredAccuracy = PositionAccuracy.High;

    //get the position of the user.
    try
    {
        //The await guarantee the calls  to be returned on the thread from which they were called

        Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(1),
            timeout: TimeSpan.FromSeconds(10)
            );

        var geoQ = new ReverseGeocodeQuery();
        geoQ.QueryCompleted += geoQ_QueryCompleted;

        if (geoQ.IsBusy == true)
        {
            geoQ.CancelAsync();
        }
        // Set the geo coordinate for the query
        geoQ.GeoCoordinate = geoposition.Coordinate;

        geoQ.QueryAsync();

    }

    catch (Exception ex)
    {
        if ((uint)ex.HResult == 0x80004004)
        {
            MessageBox.Show("position is unknown");
        }

    } 
}


void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{      
    if (e.Result.Count() > 0)
    {
        string showString = e.Result[0].Information.Name;
        showString = showString + "\nAddress: ";
        showString = showString + "\n" + e.Result[0].Information.Address.PostalCode + " " + e.Result[0].Information.Address.City; 
        showString = showString + "\n" + e.Result[0].Information.Address.Country + " " + e.Result[0].Information.Address.CountryCode;
        showString = showString + "\nDescription: ";
        showString = showString + "\n" + e.Result[0].Information.Description.ToString();

        MessageBox.Show(showString);
    }   
}

I know the problem is in the line geoQ.GeoCoordinate = geoposition.Coordinate;

But how can I pass the coordinates to geoQ.GeoCoordinate?

Thanks in adwance

windows-phone-8
reverse-geocoding
asked on Stack Overflow Sep 4, 2014 by Akhil S A • edited May 23, 2017 by Community

1 Answer

0

This is done. The geocordinate takes arguments of the type double. so all we've to do is to convert the cordiantes into double and pass it.

var currentLocationLatitude = Convert.ToDouble(geoposition.Coordinate.Latitude.ToString("0.0000000000000"));
var currentLocationLongitude = Convert.ToDouble(geoposition.Coordinate.Longitude.ToString("0.0000000000000"));

var geoQ = new ReverseGeocodeQuery();
geoQ.QueryCompleted += geoQ_QueryCompleted;

if (geoQ.IsBusy == true)
{
    geoQ.CancelAsync();
}
// Set the geo coordinate for the query

geoQ.GeoCoordinate = new GeoCoordinate(currentLocationLatitude, currentLocationLongitude);

geoQ.QueryAsync();

Thanks

answered on Stack Overflow Sep 4, 2014 by Akhil S A • edited Sep 5, 2014 by Chubosaurus Software

User contributions licensed under CC BY-SA 3.0