2006-04-15

NMEA -> MapPoint 2004 and Google Earth.

I've been playing around with GPS recievers, and the first thing I wanted to do turned out to be the hardest. Just to run through what I did, just in case anyone else wants to go through the same steps without the hours of googling and guessing. The overal aim was to get (and save) the data from my HOLOX BT-321 GPS reciever (which speaks NMEA) in some visualisable form using my Orange SPV 550 (HTC Hurricane) .

  • Saving the data: Devbuzz' forums (thanks pdcira2) contain a modification of code given in Nick Gratton and Marshall Brian's book: 'Windows CE 3.0 Application Programming' to read and parse data from a COM port and write it to a file. This code required a bit of modificaiton to make it play nice with VS2005 and Smartphone 2003, my changes will be avaliable once I get my new site up, contact me if you're impatient.
  • Log file format: You should now have a file that contains a list of lines looking something like..
    5213.8312|N|00004.2204|E|
    
    As explained on gpsinformation.org, this represents the degrees (52) and minutes (13.8312) north (N), and the degrees (0) and minutes (4.2204) east (E).
  • Applications: In this form, this information is completely useless to applications like Microsoft MapPoint 2004. Although this is incredibly poorly documented, they require the latitude and longitude to be given in degrees, as a decimal, with positive for north and east.
  • Conversion: Once you know this, the conversion is pretty trivial. Assuming that all the points are N and E, you simply need to divide each part by 100, the divide the fractional part by 0.6, eg:
    // Quick and nasty conversion for N,E NMEA data to decimal degrees.
    <?
    function conv($i)
    {
            return round(floor($i) + ($i-floor($i))/0.6, 4);
    }

    foreach (file('foo.txt') as $line) { $out = ""; $t=explode('|N|', str_replace('|E|', '', trim($line))); $out.= conv($t[0]/100); $out.= ","; $out.= conv($t[1]/100); echo $out . "\n"; }

  • Importing: Now the conversion has been done, you have a file consiting of lines that look something like:
    52.2305,0.0703
    
    • For MapPoint you can now use the 'Import Data Wizard' (Ctrl+I) on this file, telling it that the first column is latitude, the second longitude. It'll give you a load of pushpins representing your dataset, hopefully at the correct places. The example I've been using happens to be the thrilling A428/M11 junction in Cambridge.
    • For Google Earth you need to do a little more processing. You can use GPS Visualizer's KML generator to do it for you, simply delete everything in the "Or paste your data here:" box, and add "latitude,longitude" followed by the contents of your file, eg:
      latitude,longitude
      52.2305,0.0703
      ...etc.
      
      This'll generate you a "kmz" file for download, poking it suggests that it's just a zipped "kml" file, rename it to .kml.zip, extract and have a poke. You'll notice that it's just a list of space-seperated long,lat,alt, with all the altitudes being 0, pretty easy to generate yourself if you want.

Hope that saves someone a few hours.


Commenting is disabled for this post.

Read more of Faux' blog