Parsing NMEA sentences using the NMEA Parser is really easy. We just have to follow these steps:
- Contruct an NMEA sentence parser
- Call the Parse function with the raw text sentence as a parameter
- Get the return value: it is an INmeaSentence
- Cast it to GgaSentence
- Read the value of any property
This works but it requires us to know what kind of sentence we are expecting. We could use a switch on the sentence ID but it wouldn’t be really convenient. So to overcome this we can use the listeners.
We may also note that if the sentence is not correctly formatted (for instance, a bad number of fields, a wrong ID, etc.), the result will be an empty sentence object, i.e. a sentence object with only default values.