I am using raspberry pi to talk to a NMEA GPS module via serial port, everything works fine but i want to extract only latitude and longitude(i am using python language) coordinates so that i can use them in my project* (autonomous vehicle using GPS) ,i will be using a compass module to know the direction of heading.....hope u got my idea ..can anyone help me?
closed as off-topic by nc4pk, syb0rg, lenik, Impulss, hifkanotiks Dec 26 '13 at 10:40
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – nc4pk, syb0rg, lenik, Impulss, hifkanotiks
Your best bet would be using NMEA sentence $GPGGA, that's supported by most GPS receivers out there, format is like this:
$GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh 1 = UTC of Position 2 = Latitude 3 = N or S 4 = Longitude 5 = E or W 6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix) 7 = Number of satellites in use [not those in view] 8 = Horizontal dilution of position 9 = Antenna altitude above/below mean sea level (geoid) 10 = Meters (Antenna height unit) 11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. -=geoid is below WGS-84 ellipsoid) 12 = Meters (Units of geoidal separation) 13 = Age in seconds since last update from diff. reference station 14 = Diff. reference station ID# 15 = Checksum
and you may use the following code to parse:
# suppose your GPS NMEA comes as 'data' for line in data.split('\n') : if line.startswith( '$GPGGA' ) : lat, _, lon = line.strip().split(',')[2:5]
after that you may convert the strings to floats, or not...
try : lat = float( lat ) lon = float( lon ) except : # something wrong happens with your data, print some error messages pass
ps. your question is offtopic here, don't get surprised it will be deleted or moved eventually