Saturday, 6 September 2008

C# NMEA Latitude/Longitude

I'm working on an NMEA parser and was slightly confused about extracting the latitude and longitude. Most of my confusion arises as I am too lazy to bother reading any articles in detail and continually flick between browser tabs scanning pages instead of just reading them.

Anyway, say I'm trying to extract latitude and longitude from this GPRMC line:

$GPRMC,192031.764,A,4738.0175,N,12211.1861,W,0.094321,5.28,291004,,*14

The latitude is: 4738.0175,N
The longitude is: 12211.1861,W

According to wiki (http://en.wikipedia.org/wiki/Geographic_coordinate_conversion) there are three basic forms of coordinate:

  • Coordinate containing degrees (integer), minutes (integer), and seconds (integer, or real number) (DMS).

  • Coordinate containing degrees (integer) and minutes (real number) (MinDec).

  • Coordinate containing only degrees (real number) (DegDec).



NMEA sentences contain latitude and logitude of form "2". For example, the latitude above could be written as: 47°38.0175"N (48 degrees and 38.0175 decimal minutes).

Conversion to a decimal representation of the above is fairly trivial. We divide the minutes by 60 (as there are 60 minutes in one degree) and add this value to degrees. Finally we negate the value if it is in the southern hemisphere (or negate if W for longitude). So the above latitude would be:

4738.0175 = 47 + (38.075 /60) = 47.6345833