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?
-
Might be good to include any current software, data you are receiving and / or ways you have tried to get it to work. My guess would be to use grep or regex all the data for Lat: or Lon: in a log file.– James ClarkeCommented Dec 2, 2013 at 12:21
-
I have a Q&A that talks directly to using GPS on a Raspberry Pi that you might find interesting: raspberrypi.stackexchange.com/questions/68816/…– SDsolarCommented Jun 22, 2017 at 20:59
Add a comment
|
1 Answer
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