* Parses NMEA longitude format to decimal degrees. * Format: DDDMM.MMMM (degrees and minutes) * Example: "01131.000" with "E" -> 11.5167 degrees
(lonStr, hemisphere)
| 116 | * Example: "01131.000" with "E" -> 11.5167 degrees |
| 117 | */ |
| 118 | function parseLongitude(lonStr, hemisphere) { |
| 119 | if (!lonStr || lonStr.length < 5) |
| 120 | return 0; |
| 121 | |
| 122 | var degrees = parseFloat(lonStr.substring(0, 3)); |
| 123 | var minutes = parseFloat(lonStr.substring(3)); |
| 124 | var decimal = degrees + (minutes / 60); |
| 125 | |
| 126 | if (hemisphere === 'W') |
| 127 | decimal = -decimal; |
| 128 | |
| 129 | return decimal; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Validates NMEA checksum. |