Windows手机8 gps /海拔问题

时间:2012-12-11 23:08:47

标签: windows-phone-7 gps windows-phone-8 altitude

更新:使用此处的样本 - http://code.msdn.microsoft.com/wpapps/Location-sample-f11aa4e7并添加高度读数,我得到与我的代码相同的东西。准确性差50英尺。在720(正确)和300英尺之间来回走动意味着出了问题。我只是看不到...

我开始为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。 lat / long与我的位置非常接近,所以我不认为这是硬件问题。

更新:在调试器中停止检查值而不是仅打印它时,它会给出:

Altitude =评估方法时出现内部错误Windows.Devices.Geolocation.Geocoordinate.get_Altitude()

我试图搜索这个,但错误无法在互联网上找到......

文档说明高度和其他一些不保证,但它也表示如果不存在,该值将为null。我检查,它永远不会为空。它总是打印一个值,正确或约400英尺。

更新:示例代码:

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

        }
    }

1 个答案:

答案 0 :(得分:1)

您可能也会看到不同的问题,但GPS高度不是很可靠。我有几个Garmin设备,他们都到处乱跳。你真的需要一个适合高度精度的晴雨表。 以下是GPS态度不准确性GPS Elevation

的链接