× ABOUT DOWNLOADS PROJECTS WORK
    cyberpunk.sh
Profile photo

PREMCHAND CHAKKUNGAL

SENIOR SOFTWARE ENGINEER

    GET LOCATION USING AWAITABLE TASK FOR WINDOWS PHONE 8

Now a days, getting location from the device are a must feature for Mobile App developers. If you are new to Windows Phone development and have doubts in implementing location as an asynchronous operation, refer the code snippet below.


public async Task getloc()
{
            GeoData newgeodata = new GeoData(){Latitude=string.Empty, Longitude=string.Empty};
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;

            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(0), timeout: TimeSpan.FromSeconds(10));
               newgeodata.Latitude = geoposition.Coordinate.Latitude.ToString("0.0000");
               newgeodata.Longitude = geoposition.Coordinate.Longitude.ToString("0.0000");
               return newgeodata;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                   MessageBox.Show("Location is disabled in phone settings. Kindly enable it to use this app.");
                }
                return newgeodata;

            }
}

public class GeoData
{
        public string Latitude { get; set; }
        public string Longitude { get; set; }
}