Windows phone 8 gps / altitude problems

大憨熊 提交于 2019-12-11 10:02:32

问题


UPDATE: using the sample from here - http://code.msdn.microsoft.com/wpapps/Location-sample-f11aa4e7 and adding an altitude readout I get the same thing as my code. Poor accuracy is being off by 50ft. Going back and forth between 720 (correct) and 300 ft means something is wrong. I just can't see where...

I'm starting to make a GPS tracking app for windows phone 8 but something is going haywire. In my app, (and in the sample location app) i get some readings that are correct and others that are not. In general, the altitude jumps back and forth between ~95 and ~215 (with 215 being correct). The distance I'm getting is hugely inaccurate as well, quickly jumping to several miles while sitting at my desk or walking around outside.

I'm not sure what code to post, as it is identical to the sample code. If you think there is another relevant section i should post let me know and I'll add it.

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

            }


        });
    }

EDIT: I didn't mention, but the speed is perfectly fine as an fyi. the lat / long is pretty close in general to where i am as well, so I don't think it's a hardware issue.

UPDATE: When stopping in the debugger to check the value instead of just printing it, it gives this:

Altitude = An internal error has occurred while evaluating method Windows.Devices.Geolocation.Geocoordinate.get_Altitude()

I tried to search for this, but the error is nowhere to be found on the internet...

The documentation states that altitude and a few others aren't guaranteed, but it also says that the value will be null if it isn't there. I check, and it's never null. It always prints a value, either correct or ~400 ft off.

UPDATE: Sample code:

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:


You might be seeing a different issues (too) but GPS altitudes are not very reliable. I have a few Garmin devices and they all jump about all over the place. You really need a barometer for decent altitude accuracy. Here is a link on GPS attitude inaccuracy GPS Elevation



来源:https://stackoverflow.com/questions/13830053/windows-phone-8-gps-altitude-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!