I need your help. I wrote a very simple Android widget that shows the altitude which I get in the onLocationChanged method:
public void onLocationChanged(Location location) {
double myAltitude = -99;
if (location.hasAltitude()) {
myAltitude = location.getAltitude();
Log.d("SAT-LOG","Current Altitude is : "+myAltitude);
Log.d("SAT-LOG","Current Coordinatees : "+location.getLatitude()+"-"+location.getLongitude());
}
...
}
Here how I request the location update:
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.registerGnssStatusCallback(gnssActivity);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, gnssActivity);
I also tried this:
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
criteria.setAltitudeRequired(true);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
criteria.setBearingRequired(false);
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.registerGnssStatusCallback(gnssActivity);
locationManager.requestLocationUpdates(1000,1,criteria,gnssActivity,null);
I noticed that location.hasAltitude() is always true. After 10/15 minutes the value is stuck: location.getAltitude() returns the same value until the device reboot (for the record I am using a car tablet). Instead, the location latitude/longitude are always correct.
I took some log in order to share the behavior:
Timestamp Coordinates Altitude/Elevation
13:52:51.989 37.6911584,15.1052294 577,6
13:52:52.981 37.691106,15.1052072 576,6
13:52:53.990 37.6910536,15.1051881 576,3
13:52:54.985 37.6910032,15.1051709 576,1
13:52:56.019 37.6909561,15.1051632 575,4
13:52:57.032 37.6909104,15.1051537 573,7
13:52:57.993 37.6908579,15.105138 572,6
13:52:58.984 37.6908022,15.105121 572,1
13:52:59.982 37.690747,15.1051034 571,5
13:53:00.984 37.6906914,15.1050854 571,2
13:53:02.021 37.6906406,15.1050694 571,9
13:53:02.974 37.6906027,15.1050565 572,2
13:53:03.983 37.6905802,15.1050451 621,7000122 <-Invalid Values
13:53:04.984 37.6905657,15.1050349 621,7000122
13:53:05.985 37.6905537,15.1050258 621,7000122
13:53:06.990 37.6905363,15.1050178 621,7000122
13:53:07.982 37.6905103,15.1050077 621,7000122
13:53:08.981 37.6904757,15.1049966 621,7000122
13:53:10.027 37.6904339,15.1049828 615,6000366
13:53:10.982 37.6903825,15.1049643 615,6000366
13:53:11.982 37.6903202,15.1049418 615,6000366
13:53:12.980 37.6902507,15.104916 615,6000366
13:53:14.021 37.6901782,15.1048888 615,6000366
13:53:14.988 37.690104,15.10486 615,6000366
13:53:15.985 37.6900287,15.1048412 615,6000366
13:53:16.990 37.6899508,15.1048195 615,6000366
...
...
...
13:54:34.982 37.6830799,15.1036726 615,6000366
13:54:35.986 37.6829489,15.1036597 615,6000366
13:54:36.984 37.6828161,15.1036388 615,6000366
13:54:37.988 37.6826812,15.1036125 615,6000366 <- Invalid Values ends here
13:54:38.985 37.6825483,15.1035831 551,6 <-Valid Values again
13:54:39.989 37.6824177,15.1035502 551,6
13:54:40.986 37.6822904,15.1035137 551,7
13:54:41.989 37.6821635,15.1034749 551,5
13:54:42.980 37.6820341,15.1034429 551,9
13:54:43.986 37.6818938,15.1034188 551,4
13:54:44.986 37.6817466,15.1034 551,1
As you can see from 13:53:03.983 to 13:54:37.988 the methods returns invalid altitude values (the coordinates are right). More or less, 95 invalid samples (consecutive). In the log at 14:04 I have another sequence of 99 invalid values.
If I open the App GPSTest, I see the correct value of altitude. Can someone help me to understand the issue ? Is there a better way to get the altitude/elevation?