I've connected a USB GPS device and am able to write them to a file using gpspipe.

There are limitations though:

  • does not record in KML
  • existing tools for conversion to KML don't seem to interpret timestamps

How can I record GPS data to KML format, either on the fly or preferably when I stop writing?


gpspipe -r should produce clean NMEA data, but the version provided with Raspbian adds some JSON noise at the start that really doesn't belong. To output just NMEA sentences from gpspipe, this is what worked for me:

gpspipe -r | grep '^\$G' | tee test3.nmea

This filters out just the NMEA data, and copies the output to the screen and to the file test3.nmea.

You can convert this to KML using gpsbabel:

gpsbabel -i nmea -f test3.nmea -o kml -F test3.kml

Each of the points includes a timestamp, f'rinstance:

            <tr><td>Longitude: -79.264922 </td></tr>
            <tr><td>Latitude: 43.730687 </td></tr>
            <tr><td>Altitude: 502.953 ft </td></tr>
            <tr><td>Speed: 1.4 mph </td></tr>
            <tr><td>Heading: 221.5 </td></tr>
            <tr><td>Time: 2012-12-15T21:27:34Z </td></tr>

If you want something that Google Earth can still read, but has cleaner metadata, I'd recommend GPX. You can make it with:

gpsbabel -i nmea -f test3.nmea -o gpx -F test3.gpx

Each trackpoint will look a bit like:

<trkpt lat="43.730533333" lon="-79.265021667">

These results were tested and generated on a Raspberry Pi running latest Raspbian, with gpsd reading from a Pharos GPS-500 on /dev/ttyUSB0.

Does your GPS have a satellite fix? Check with cgps/xgps, and see that the Status is at least '2D Fix'. If you're indoors and haven't warm-started your GPS receiver, you may never get a fix. You'll still get NMEA data, just it doesn't contain $GPRMC position data.


Gpsbabel should be the best solution for you. Here I found documentation for you about kml in gpsbabel. For more information the best way will be check man pages after install it on your pi.

You should be able to convert files easly. Here is example for other format:

gpsbabel -t -i kml -f one.kml -x track,title=$name -o gpx -F one.gpx
gpsbabel -t -i gpx -f one.gpx -o garmin -F usb:0

Docs: http://www.gpsbabel.org/htmldoc-1.4.2/fmt_kml.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.