1

Im работает с телефоном Windows 8.1 геолокация. Проблема, которую я сейчас имею в том, что мой код показывает только первые числа моей координаты. Пример: если координата «41.233», приложение показывает только «41.00». Мне нужно, чтобы это было как можно точнее. В случае, если это имеет значение, я использую эмулятор Windows Phone 8.1, чтобы попробовать приложение, а не фактический телефон.Точный телефон Windows 8.1 геолокация?

Мой код:

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

Спасибо за вашу помощь!

+0

Ваш код прекрасно работает для меня, когда я запустить маршрут в эмуляторе. Как вы генерируете координаты? Если вы установили на вкладке «Расположение» эмулятора то, что они там установили? –

ответ

0

В этой точке LatitudeTxt.Text = geoposition.Coordinate.Latitude.ToString("0.00"); LongitudeTxt.Text = geoposition.Coordinate.Longitude.ToString("0.00");

Вы указали, что у вас есть 0,00 десятичные, для большей точности, вы должны поставить 0.000000

Смежные вопросы