Created
April 4, 2019 17:12
-
-
Save skyksandr/63845d091088cd956b362a8ee7717b63 to your computer and use it in GitHub Desktop.
Get coordinates from NMEA GPRMC in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // DATA FORMAT | |
| // | |
| // RMC - NMEA has its own version of essential gps pvt (position, velocity, time) data. It is called RMC, The Recommended Minimum, which will look similar to: | |
| // | |
| // $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A | |
| // | |
| // Where: | |
| // RMC Recommended Minimum sentence C | |
| // 123519 Fix taken at 12:35:19 UTC | |
| // A Status A=active or V=Void. | |
| // 4807.038,N Latitude 48 deg 07.038' N | |
| // 01131.000,E Longitude 11 deg 31.000' E | |
| // 022.4 Speed over the ground in knots | |
| // 084.4 Track angle in degrees True | |
| // 230394 Date - 23rd of March 1994 | |
| // 003.1,W Magnetic Variation | |
| // *6A The checksum data, always begins with * | |
| function nmeaParser(str) { | |
| const KNOTS_IN_MS = 1.9438 | |
| const nmea = str.split(',') | |
| function parseLatitude() { | |
| const degrees = Number(nmea[3].substring(0, 2)) | |
| const seconds = Number(nmea[3].substring(2)) | |
| const negate = this.nmea[4].toUpperCase() === 'S' | |
| return (degrees + seconds / 60) * (negate ? -1 : 1) | |
| } | |
| function parseLongitude() { | |
| const degrees = Number(nmea[5].substring(0, 3)) | |
| const seconds = Number(nmea[5].substring(3)) | |
| return degrees + seconds / 60 | |
| } | |
| return { lat: parseLatitude(), lng: parseLongitude() } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment