How does getAltitude() of Android GPS Location Works
Asked Answered
K

5

7

HI

I tried to implement a simple GPS tracker. Therefore is used

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);  

Then i used the

public void onLocationChanged(Location location) {

method to read the altitude of my current location.

But i dont really know what Location.getAltitude() returns. The document says it returns the altitude. But is this in meters? or feets? if i put the phone on the desk next to me, this value changes between 500 and -500??

How does this really work???

Komsa answered 7/5, 2010 at 22:1 Comment(1)
Still, this isn't something best left to assuming (we all know where assuming gets us in programming). Especially since the country you speak of is where google is headquarted. Lets just agree that the documentation could be improved.Polar
M
25

The altitude value you get is in meters from the gps (WGS84) reference ellipsoid and not from the geoid.

From my own experience the GPS are really bad at altitude values.

I read this on the GPS Status FAQ:

GPS does not report the height above the mean sea level, rather the GPS system compares the height to the WGS84 reference ellipsoid which may be above or below the actual sea level. In different parts of the earth it can be off by more than 200 meters (depending on the mass distribution of Earth). For example the geoid's surface around Florida is above the mean sea level by a good 30-40 meters, which means that standing on the shore would show you -30m as altitude. This is normal, and not an error, and caused by the fact that the altitude is relative to an artificial reference surface and not to the sea level. If you are interested in this topic, I recommend to read Mean Sea Level, GPS, and the Geoid.

Malinger answered 9/5, 2010 at 8:5 Comment(4)
Is it fair to say that the measurements are "precise but not accurate" in a fairly localized setting? In other words, can GPS be used to accurately measure relative altitude between nearby points?Polar
@snapfractalpop: No, GPS is not good for altitude. You should use a barometer to measure the altitude, newer Android phones has that, e.g. Nexus Galaxy.Malinger
thank you, good to know. would a barometer be problematic due to weather disturbances?Polar
what the difference from Location.getAltitude() because from the doc it's also The altitude of this location in meters above the WGS84 reference ellipsoid.. and addNmeaListener ?Cuckoo
H
6

old post, i rekon, but someone might still be interested. while listening to GPS, you can parse NMEA GPGGA sentence (http://aprs.gids.nl/nmea/#gga), in which there is the geoid height (Height of geoid above WGS84 ellipsoid). just subtract this heigh from the getAltitude returned value, one and you'll have a more accurate elevation value.

Edit after several months of usage and feedback received from users of my app

A better solution is to get directly the elevation value in the GPGGA sentence:

double GGA_ALTITUDE = 0d;
private static final String NMEA_GGA = "$GPGGA";    
private static final int altitude_element_id = 9;

@Override
public void onNmeaReceived(long timestamp, String nmea) {
    foundSats = true;
    // check that this is an RMC string
    if (nmea.startsWith(NMEA_GGA)) {
        String[] tokens = nmea.split(",");
        try {
            // get orthometric elevation
            String elevation = tokens[altitude_element_id];             
            if (!elevation.equals("")) {
                Log.d("NMEA", "ortho elev: " + ortho);
                GGA_ALTITUDE = Double.parseDouble(elevation);                   
            }
        } catch (Exception ex) {
            Log.e("NMEA", "onNmeaReceived: "
                    + ex.getMessage());

            onNmeaException(ex.getMessage());               
            ex.printStackTrace();
        }
    } 
}
Homochromatic answered 6/6, 2013 at 13:10 Comment(5)
If the field is filled, which it does not have to be, and if the sentence is even output, which it does not have to be either and if there is NMEA output at all; cheaper Android devices don't have it at all.Octave
Hi Jan, of course as you can see in my code, some checks are to be made before reading that value. I guess that in cheaper devices, the onNmeaReceived event is never fired ;)Homochromatic
There are indeed many devices that don't return NMEA at all or only return limited information in it.Octave
How to find the distance from android phone to object which is placed on table?? Can i use this method or we have some other options?Hereditament
what the difference from Location.getAltitude() because from the doc it's also The altitude of this location in meters above the WGS84 reference ellipsoid.. But values are different still...Cuckoo
K
1

I assume that your desk is located inside a building. If you get a GPS fix in a building you shouldn't expect the accuracy to be very high. Have to tried getting the accuracy of the fix by calling getAccuracy()?

Krysta answered 9/5, 2010 at 7:30 Comment(1)
yes its located in a building but i put it on the window frame ;) thanks for the getAccuracy tipKomsa
M
1

Gps simply measures the time a known signal is sent from several satellites. The more satellites in view of your Gps receiver the more accurate your position will be determined relative to those satellites. While the system is prone to some error- background noise (the satellite signal is relatively weak and space is relatively noisy), low precision time piece in your receiver, GDOP: geometric dillution of precision (all satellites grouped in one corner of sky), refraction of the signal due to the ionosphere changing heights,- overall it is very accurate in determining your distance from a satellite. Geometrically you need at least 3 satellites in view to get a position and a 4th to get altitude. More satellites contribute to greater accuracy and in some more complex receivers (not our phones but specifically aviation applications) RAIM: receiver autonomous integrity monitoring, is provided to forecast accuracy in an area and time ie before an aircraft lands...

Altitude is problematic for the gps system because the earth does not curve at mathematical constant. So while the system knows where you are relative to the satellite it must now overlay that on a mathematical model of the earth. In aviation the more accurate Gps receivers must have altitude supplemented with barometers and in some receivers enhanced position due to a known surveyed point comparison (WAAS and LAAS).

Marasco answered 14/5, 2014 at 14:26 Comment(0)
N
0

This occur where you use the LocationManager.NETWORK_PROVIDER like location provider, ensure that you use LocationManager.GPS_PROVIDER like your favorite Gps Provider.

Nordgren answered 10/10, 2016 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.