Ruby NMEA parser
C++ Ruby C
Latest commit f3e2d58 Mar 19, 2009 @maxlapshin added gemspec


Author::    Max Lapshin  (
Copyright:: Copyright (c) 2007 Max Lapshin, Getalime
License::   Distributes under the same terms as Ruby

To use NMEA parser, you should somehow get data stream from Yor gps device.
For example, You can use ruby-serialport (which seems to be dead, but working).
The example on Mac with installed USB-Serial driver:

	require 'serialport'
	require 'nmea'
	@sp ="/dev/tty.usbserial", 4800, 8, 1, SerialPort::NONE)
	@handler =
	while(@sentence = @sp.gets) do
	  NMEA.scan(@sentence, @handler)

NMEAHandler is a user class, that implements following interface:

	class NMEAHandler
	  def rmc(time, latitude, longitude, speed, course, magnetic_variation)
	    # read further about types of latitude and longitude
	  def gsv(flag, satellites)
	  def gsa(mode_state, mode, satellites, pdop, hdop, vdop)
	  def gga(time, latitude, longitude, gps_quality, active_satellite_count, gsa_hdop, altitude, geoidal_height, dgps_data_age, dgps_station_id)

As you can see, the following NMEA sentences are supported currently: $GPRMC, $GPGSV, $GPGSA, $GPGGA.
If you need more, please contact me and provide me with several examples. I will add support for them.
NMEA::scan will not try to call unexistent method on your handler, thus you can implement only those
methods in your handler, you need to.

GSV handler has parameter flag. This flag can take one of the following values: <code>:start</code>, <code>:continue</code>
 and <code>:finish</code>. GSV messages appears in packs of several sentences, but NMEA::scan is stateless, 
thus your NMEAHandler should keep accumulate these messages.

It is important to mention, that NMEA::scan assumes, that You have classes GPS::Latitude and GPS::Longitude,
which initializer, takes two arguments: degrees and minutes. You can use this example:

	module GPS
	  AngleValue = :degrees, :minutes

	  class AngleValue
	    def to_s
	      "%d %.4f%s" % [degrees.abs, minutes, symbol]

	  class Latitude < AngleValue
	    def symbol
	      degrees >= 0 ? "N" : "S"
	  class Longitude < AngleValue
	    def symbol
	      degrees >= 0 ? "E" : "W"

Supported devices.

Ruby NMEA has full support of Globalsat BU-353 device (

NMEA syntax is assumed to be as in document nmea.html, taken from