2012-12-11 139 views
1

更新:使用此處的示例 - http://code.msdn.microsoft.com/wpapps/Location-sample-f11aa4e7並添加海拔高度讀數我獲得與我的代碼相同的內容。準確度不佳正在減少50英尺。在720(正確)和300英尺之間來回移動意味着錯誤。我只是看不到在哪裏...Windows phone 8 gps /海拔高度問題

我開始爲windows phone 8製作一個GPS跟蹤應用程序,但有些事情會發生干擾。在我的應用程序中(和示例位置應用程序中),我得到了一些正確的讀數,而其他的讀數沒有。一般來說,高度在〜95和〜215之間來回跳動(215是正確的)。我得到的距離也非常不準確,當坐在我的辦公桌前或在外面走動時,很快跳到了幾英里。

我不確定要發佈什麼代碼,因爲它與示例代碼相同。如果您認爲我應該發佈另一個相關版塊,請告訴我,我將添加它。

double maxSpeed = 0.0; 
    double maxAlt = -9999999.0; 
    double minAlt = 9999999.0; 
    double curDistance = 0.0; 
    GeoCoordinate lastCoord = null; 
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true) 
     { 
      // The user has opted out of Location. 
      return; 
     } 


     if (App.Geolocator == null) 
     { 
      // Use the app's global Geolocator variable 
      App.Geolocator = new Geolocator(); 
     } 

     App.Geolocator.DesiredAccuracy = PositionAccuracy.High; 
     //App.Geolocator.MovementThreshold = 1; // The units are meters. 
     App.Geolocator.ReportInterval = 1000; 
     //App.Geolocator.DesiredAccuracyInMeters = 50; 
     App.Geolocator.StatusChanged += geolocator_StatusChanged; 
     App.Geolocator.PositionChanged += geolocator_PositionChanged; 

     /* 
     geolocator = new Geolocator(); 
     geolocator.DesiredAccuracy = PositionAccuracy.High; 
     //geolocator.MovementThreshold = 1; // The units are meters. 
     geolocator.ReportInterval = 1000; 
     geolocator.StatusChanged += geolocator_StatusChanged; 
     geolocator.PositionChanged += geolocator_PositionChanged; 
     * 
     * */ 
     logging = true; 

     startTime = DateTime.Now; 


    } 
public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate) 
    { 
     return new GeoCoordinate 
      (
      geocoordinate.Latitude, 
      geocoordinate.Longitude, 
      geocoordinate.Altitude ?? Double.NaN, 
      geocoordinate.Accuracy, 
      geocoordinate.AltitudeAccuracy ?? Double.NaN, 
      geocoordinate.Speed ?? Double.NaN, 
      geocoordinate.Heading ?? Double.NaN 
      ); 
    } 
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args) 
    { 
     Dispatcher.BeginInvoke(() => 
     { 
      if (lastCoord == null) 
      { 
       lastCoord = ConvertGeocoordinate(args.Position.Coordinate); 
      } 
      DateTime currentTime = DateTime.Now; 

      TimeSpan totalTime = currentTime - startTime; 

      timeValue.Text = totalTime.ToString(@"hh\:mm\:ss"); 


      System.Diagnostics.Debug.WriteLine(args.Position.Coordinate.Altitude.ToString()); 


      GeoCoordinate thisLocation = ConvertGeocoordinate(args.Position.Coordinate); 



      if (true) //units check true = standard 
      { 
       double speed = (double)thisLocation.Speed; 
       speed *= 2.23694; //m/s -> mph 
       speedValue.Text = speed.ToString("0"); 

       double alt = (double)thisLocation.Altitude; 
       if (alt > maxAlt) 
       { 
        maxAlt = alt; 
       } 
       if (alt < minAlt) 
       { 
        minAlt = alt; 
       } 
       /* 
       double currentAlt = (maxAlt - minAlt); 
       currentAlt *= 3.28084; //m -> ft 
       * */ 
       alt *= 3.28084; 
       altValue.Text = alt.ToString("0"); 

       double distance = thisLocation.GetDistanceTo(lastCoord); 

       curDistance += distance; 

       distance = curDistance * 0.000621371; // m -> miles 

       distanceValue.Text = distance.ToString("0.00"); 

       distanceUnits.Text = "(mi)"; 
       speedUnits.Text = "(mph)"; 
       altUnits.Text = "(ft)"; 

      } 


     }); 
    } 

編輯:我沒有提到,但作爲一個fyi速度是非常好的。緯度/長度通常非常接近我的位置,所以我不認爲這是硬件問題。

更新:當在調試器停止來檢查值,而不是僅僅將其打印,它給出了這樣的:

海拔=發生內部錯誤而評價方法Windows.Devices.Geolocation.Geocoordinate.get_Altitude()

我試圖尋找這一點,但這個錯誤是無處可在互聯網上找到...

該文件指出,高度和其他幾個人都不能保證,但同時也表示,值如果不存在,它將爲空。我檢查,並且它從不爲空。它總是打印一個值,要麼是正確的,要麼是400英尺。

UPDATE:示例代碼:

void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args) 
    { 
     System.Diagnostics.Debug.WriteLine(args.Position.Coordinate.Altitude.ToString()); 


     if (!App.RunningInBackground) 
     { 
      Dispatcher.BeginInvoke(() => 
      { 
       LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString("0.00"); 
       LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString("0.00"); 

      }); 
     } 
     else 
     { 
      Microsoft.Phone.Shell.ShellToast toast = new Microsoft.Phone.Shell.ShellToast(); 
      toast.Content = args.Position.Coordinate.Latitude.ToString("0.00"); 
      toast.Title = "Location: "; 
      toast.NavigationUri = new Uri("/MainPage.xaml", UriKind.Relative); 
      toast.Show(); 

     } 
    } 
+0

我有同樣的經驗,但不是一個解決方案。 – Guldan

回答

1

您可能會看到一個不同的問題(太多),但GPS海拔都不是很可靠的。我有幾個Garmin設備,他們都在這個地方跳。你真的需要一個晴雨表來提高體面的高度準確性。 這裏是GPS姿態不準確的鏈接GPS Elevation