UPDATE: using the sample from here - http://code.msdn.microsoft.com/wpapps/Location-sample-f11aa4e7 and adding the height readings, I get the same as my code. Poor accuracy is reduced by 50 feet. The transition between 720 (correct) and 300 feet means that something is wrong. I just can't see where ...
I'm starting to make a GPS tracking application for a phone with a phone of 8, but something is happening with haywire. In my application (and in the location application) I get some data that is correct, while others do not. In general, the height jumps back and forth between ~ 95 and ~ 215 (if correct, 215). The distance that I get is also very inaccurate, quickly jumping a few miles, sitting at my table or walking along the street.
I am not sure which code to send, since it is identical to the sample code. If you think there is another relevant section that I should publish, let me know and I will 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 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)
EDITOR: I did not mention, but the speed is beautiful, like fyi. lat / long is pretty close overall to where I am too, so I don't think this is a hardware problem.
UPDATE: when stopping in the debugger to check the value, instead of just printing it, it gives the following:
Height = An internal error occurred while evaluating the Windows.Devices.Geolocation.Geocoordinate.get_Altitude () method
I tried to find this, but errors could not be found on the Internet ...
The documentation states that the height and several others are not guaranteed, but also states that the value will be null if it does not exist. I check and it never matters. It always prints the value, either correctly or ~ 400 feet.
UPDATE: Code example:
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(); } }