skip to content
AdaWiki
User Tools
Log In
Site Tools
Search
Tools
Show page
Old revisions
Backlinks
Recent Changes
Media Manager
Sitemap
Log In
>
Recent Changes
Media Manager
Sitemap
You are here:
start
»
tutorials
»
products
»
ultimategps
»
index.html
Trace:
tutorials:products:ultimategps:index.html
====== Moved! ====== The Ultimate GPS tutorial has moved to [[http://learn.adafruit.com/adafruit-ultimate-gps|http://learn.adafruit.com/adafruit-ultimate-gps]] ====== LOCUS Parser ====== The GPS LOCUS parser is still here though, use it below! **Copy and paste all the text after the —-'s (starting with $PMTKLOX,0,86*67 and ending with $PMTK001,622,3*36)** <html> <script type="text/javascript" src="http://ladyada.net/wiki/lib/scripts/jquery-1.7.2.min.js"></script> <script type="text/javascript"><!--//--><![CDATA[//><!-- $(document).ready(function(){ $("#parse").click(function(e){ var ut = $("#unparsed_text").val(); ut = ut.replace(/[\s\xA0]+/g,''); ut_arr = ut.split('$PMTKLOX,'); //start and finish started = 0; ended = 0; out_string = ''; out_xml = ' \n <dataset2 xmlns="xsdbooks">'; out_kml_path = '<?xml version="1.0" encoding="UTF-8"?> \n \ <kml xmlns="http://www.opengis.net/kml/2.2"> \n \ <Document> \n \ <name>GPS Path</name> \n \ <description>Path parsed from GPS data.</description> \n \ <Style id="yellowLineGreenPoly"> \n \ <LineStyle> \n \ <color>7f00ffff</color> \n \ <width>4</width> \n \ <gx:labelvisibility>0</gx:labelvisibility> \n \ </LineStyle> \n \ <PolyStyle> \n \ <color>7f00ff00</color> \n \ </PolyStyle> \n \ </Style> \n \ <Placemark> \n \ <scale>0</scale> \n \ <name>Begin</name> \n \ <description>Start GPD Data</description> \n \ <styleUrl>#yellowLineGreenPoly</styleUrl> \n \ <LineString> \n \ <extrude>1</extrude> \n \ <tessellate>1</tessellate> \n \ <altitudeMode>absolute</altitudeMode> \n \ <coordinates>'; count = 0; polyline_points = new google.maps.MVCArray(); jQuery.each(ut_arr, function(index, value){ if(value.charAt(0) == '0'){ // start parse! started = index; } else if(value.charAt(0) == '2'){ ended = index; } else if(value.charAt(0) == '1'){ utt_arr = value.split(','); // remove 6 LOCUS checksum utt_arr[-1] = utt_arr[1].slice(0,8); if(utt_arr.length == 26) { utt_arr = utt_arr.slice(2); for (var i = 0; i < 6; i++) { count++; loc = utt_arr.slice(i*4, (i*4)+4); utc_date = new Date(parseInt(byteFlip(loc[0]), 16) * 1000); utc = utc_date.toString(); type = loc[1].slice(0, 2); lat = hex2float(byteFlip( loc[1].slice(2) + loc[2].slice(0,2) )); long = hex2float(byteFlip( loc[2].slice(2) + loc[3].slice(0,2) )); height = parseInt(byteFlip( loc[3].slice(2, 6) ) , 16); checksum = loc[3].slice(6); type_string = ''; if (type == '02'){ type_string = '3D-Fix'; } else{ type_string = type; } if ( !(lat.toFixed() == 0 || long.toFixed() == 0 ) && lat <= 90 && lat >= -90 && long >= -180 && long <= 180 ) { out_string = out_string + utc + ' ' + type + ' ' + lat + ' ' + long + ' ' + height + ' ' + "\n"; out_xml = out_xml + " \ <Count Data=\""+count+"\">\n \ <UTC>"+utc+"</UTC>\n \ <FixType>"+type_string+"</FixType>\n \ <Lat>"+lat.toFixed(6)+"</Lat>\n \ <Lon>"+long.toFixed(6)+"</Lon>\n \ <HGT>"+height+"</HGT>\n \ </Count> \n"; out_kml_path = out_kml_path + long + ',' + lat + ',' + height + '\n'; googleMapArray[0].map.markerArray[count] = new google.maps.Marker({ position: new google.maps.LatLng(lat, long), clickable: true, visible: true, title: 'GPS Data #' + count, }); googleMapArray[0].map.markerArray[count].setMap(googleMapArray[0].map); polyline_points.push(new google.maps.LatLng(lat, long)); } } } else { out_string = out_string + "\n Line Parse Error " + utt_arr.length + " \n";; } } }); out_xml = out_xml + "\n </dataset2>"; out_kml_path = out_kml_path + "\n </coordinates>\n \ </LineString>\n \ </Placemark>\n \ </Document>\n \ </kml>\n"; //alert(out_xml); $("#output_xml").html(htmlEntities(out_xml)); $("#output_kml_path").html(htmlEntities(out_kml_path)); polyline = new google.maps.Polyline(); polyline.setPath(polyline_points); polyline.setMap(googleMapArray[0].map); googleMapArray[0].map.setCenter(new google.maps.LatLng(lat, long)); googleMapArray[0].map.setZoom(12); }); }); function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } function byteFlip(hexString){ returnString = ''; for(i = 0; i< hexString.length; i+=2) { returnString = hexString.slice(i, i+2) + returnString; } return returnString; } function hex2float(hexString) { num = parseInt(hexString, 16); var sign = (num & 0x80000000) ? -1 : 1; var exponent = ((num >> 23) & 0xff) - 127; var mantissa = 1 + ((num & 0x7fffff) / 0x7fffff); number = sign * mantissa * Math.pow(2, exponent); return number; } //--><!]]></script> <textarea id="unparsed_text" rows="30" cols="100" ></textarea> <br /> <input type="button" id="parse" value="Parse Data"/> <br /> <table> <tr> <td>XML Output: <br /><textarea id="output_xml" rows="30" cols="100"></textarea></td> <td>KML Output: <br /><textarea id="output_kml_path" rows="30" cols="100"></textarea></td> </tr> </table> </html> <googlemap3 width="80%" height="400px" type="normal" helper="off"> </googlemap3>
/home/ladyada/public_html/wiki/data/pages/tutorials/products/ultimategps/index.html.txt
· Last modified: 2016/01/28 18:05 (external edit)
Page Tools
Show page
Old revisions
Backlinks
Back to top