3

Hello I am currently using BU-353 S4 USB GPS in my Linux,

the command,

cgps -s

Output various parameters including, Time, Latitutde, Longitute, Speed, Heading etc...

is there any way to output only Longitude and Latitude instead of the complete details ?

I have gone through all the available arguments of cgps command and as far as I can tell, this command only output the complete table.

1
  • What about reading the NMEA data directly from serial port and parsing $GPGGA?
    – yegorich
    Dec 16 '13 at 15:21
6

You can use awk to parse $GPGGA directly. See example below:

echo $GPGGA,001038.00,3334.2313457,N,11211.0576940,W,2,04,5.4,354.682,M,-26.574,M,7.0,0138*79 | awk -F"," '{print $3,$5}'

would output:

3334.2313457 11211.0576940

Update

Try something like this:

awk -F"," '/GGA/ {print $3,$5}' /dev/ttyUSB0

This command should read from /dev/ttyUSB0 (substitute with proper one), find lines with GGA and parse them.

4
  • This is exactly what i want , but could you please elaborate your line of code ? Dec 16 '13 at 15:40
  • 1
    @Xufyan -F"," defines a field separator, i.e. ',' in our case. '{print $3,$5}' prints fields 3 and 5 i.e. our Longitude and Latitude. First field is $GPGGA ,second - the time and the third one is Latitude according to NMEA. All you have to is to read from USB serial port and find GPGGA lines. See updated answer.
    – yegorich
    Dec 16 '13 at 15:47
  • 1
    @Xufyan I've tested it with my GPS receiver and put the final command to my answer. As long as cat /dev/ttyUSB0 is functioning, my script should also work. Learned something new about awk, pipes etc. myself :-)
    – yegorich
    Dec 16 '13 at 16:43
  • 1
    Done already , actually i didn't convert from binary to NMEA this is why the issue caused, i had to run this command before proceeding. gpsctl -f -n /dev/ttyUSB0 Dec 16 '13 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.