Parsing GPS Strings with Python

You have to look for the GPGGA string in the lines of text coming in from the GPS device. Each string ends in cr/lf.

The format for the $GPGGA message string is:

$GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,g.g,z,t.t,iii*CC

hhmmss.ss in UTC (coordinated universal time zone).
ddmm.mmmm,N latitude of the GPS position fix
dddmm.mmmm,W longitude of the GPS position fix
q the quality of the GPS fix (1 = fix, but no differential correction)
ss number of satellites being used
y.y horizontal dillution of precision
a.a,M GPS antenna altitude in meters
g.g,M geoidal separation in meters
t.t age of the deferrential correction data
iii deferential station’s ID
* checksum for the sentence

Use the split() or re module to get what you need.

items = incomingString.split(‘,’)
lattiitude = items[2]
if items[3] == ‘N’: print ” I am in the northern hemisphere “