How does getAltitude() of Android GPS Location Works

后端 未结 5 1768
后悔当初
后悔当初 2020-12-31 23:30

HI

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

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocatio         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 00:16

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

提交回复
热议问题