If you don't have fancy operating system or API sitting between you and your GPS module, you very likely have to deal with NMEA data sooner or later to get your location. For more complete reference, this page has quite nice list of move common data packages your GPS may send to you.
By default most receivers send out much more than you need, but the extra messages can be turned off or ignored. Typically GPRMC is all you need to get your location.
It will look like this (copy from above page).
$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62
Or possibly like this:
$GPRMC,180633.059,A,6543.8270,N,02631.0022,E,2.20,182.21,030219,,,A*62
The format depends on device used and is kinda historical artifact, as working with it is kinda painful.
First thing you want is validity field, second after header, here A. A means that GPS fix is valid and rest of the data is valid. V means invalid, so ignore messages with that flag.
Then comes latitude in a somewhat weird format: 6543.8270,N . This actually means 65 degrees and 43.8270 minutes north. Minutes go from 0.000 to 59.9999 and back to zero, so if you want to do anything else with this data than just to store it, you pretty much will have to convert this figure to decimal degrees first. And of course same applies to longitude. Not difficult, but this may come as a nasty surprise if you are just getting started with GPS.
Note also that number of decimals on those message examples are different. If you are working with floating point numbers, this isn't too much of a trouble, but if you want to do this with integers, it gets a bit messier as you have to take care to keep number of decimals the same when processing the data. Fortunately it seems that at least this is same within a device; GPS receivers don't suddenly change from, say, 2 decimal places to 4.
So there you go, quick primer on finding yourself with a help of shiny new GPS module!
Ei kommentteja:
Lähetä kommentti