Accurate Windows phone 8.1 geolocation?

1

Im working with windows phone 8.1 geolocation. The problem that I currently have is that my code only shows the first numbers of my coordinate. Example: If the coordinate is "41.233" the app only shows "41.00" . I need it to be as accurate as possible. In case it matters, im using windows phone 8.1 emulator to try the app, not an actual phone.

My code:

public sealed partial class MainPage : Page
{
    bool shouldSend = false;
    DispatcherTimer timer = new DispatcherTimer();

    public MainPage()
    {
        this.InitializeComponent();
        this.NavigationCacheMode = NavigationCacheMode.Required;

    }

    private async Task GetLocation()
    {
        Geolocator geolocator = new Geolocator();
        geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;

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

            LatitudeTxt.Text  = geoposition.Coordinate.Latitude.ToString("0.00");
            LongitudeTxt.Text = geoposition.Coordinate.Longitude.ToString("0.00");
            LatLonTxt.Text = LatitudeTxt.Text + ", " + LongitudeTxt.Text;                
            var speed = geoposition.Coordinate.Speed.ToString();
            ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;


            string result = "";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                "http://proyecto-busways.rhcloud.com/colectivos?p=lta123&l=80&d=moyano&lat=" + LatitudeTxt.Text + "&lon=" + LongitudeTxt.Text + "&v=" + speed + "&Accion=Agregar");
            request.ContinueTimeout = 4000;

            request.Credentials = CredentialCache.DefaultNetworkCredentials;

            using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //To obtain response body
                    using (Stream streamResponse = response.GetResponseStream())
                    {
                        using (StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8))
                        {
                            result = streamRead.ReadToEnd();
                        }
                    }
                }
            }


        }
        catch (Exception ex)
        {
            ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if ((uint)ex.HResult == 0x80004004)
            {
                // the application does not have the right capability or the location master switch is off
             }
            //else
            {
                // something else happened acquring the location
            }
        }

    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.
    /// This parameter is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        // TODO: Prepare page for display here.

        // TODO: If your application contains multiple pages, ensure that you are
        // handling the hardware Back button by registering for the
        // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
        // If you are using the NavigationHelper provided by some templates,
        // this event is handled for you.
    }

    private async void StartSending_Click(object sender, RoutedEventArgs e)
    {
        await GetLocation();

        timer.Tick += timer_Tick;
        timer.Interval = new TimeSpan(0, 0, 5);
        timer.Start();
        StartSending.IsEnabled = false;
    }

    async void timer_Tick(object sender, object e)
    {
        ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Visible;
        await GetLocation();

    }

    private void EndSending_Click(object sender, RoutedEventArgs e)
    {
        timer.Tick -= timer_Tick;
        timer.Stop();
        StartSending.IsEnabled = true;
        EndSending.IsEnabled = false;
    }

    private void GPS_Tapped(object sender, TappedRoutedEventArgs e)
    {
        Frame.Navigate(typeof(ContactPage));
    }
}

Thanks for your help!

windows-phone-8
geolocation
windows-phone-8.1
compass-geolocation
asked on Stack Overflow Feb 17, 2015 by Giani • edited Feb 18, 2015 by Kulasangar

2 Answers

0

Did you try out the Geolocator.DesiredAccuracyInMeters property?

 geolocator.DesiredAccuracyInMeters = 3;

Reference & Sample

answered on Stack Overflow Feb 18, 2015 by Kulasangar • edited May 23, 2017 by Community
0

In this point LatitudeTxt.Text = geoposition.Coordinate.Latitude.ToString("0.00"); LongitudeTxt.Text = geoposition.Coordinate.Longitude.ToString("0.00");

You indicated that you have 0.00 decimals, for more accuracy you should put 0.000000


User contributions licensed under CC BY-SA 3.0