1

I did run a command from the python program which is related to GPS.

sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock
cgps -s

Now i want to use this information like latitude and longitude in my python code. How can i get these data? And these latitude and longitude values will be continuously varying. So can i get the value using python? Output from the above command gives like this

┌───────────────────────────────────────────┐┌─────────────────────────────────┐
│    Time:       2018-04-10T05:49:46.000Z   ││PRN:   Elev:  Azim:  SNR:  Used: │
│    Latitude:    12.945873 N               ││   1    08    177    23      Y   │
│    Longitude:   77.569187 E               ││   3    35    195    29      Y   │
│    Altitude:   913.1 m                    ││   7    22    313    09      Y   │
│    Speed:      1.2 kph                    ││   8    54    127    24      Y   │
│    Heading:    0.0 deg (true)             ││   9    44    335    25      Y   │
│    Climb:      0.0 m/min                  ││  11    20    168    21      Y   │
│    Status:     3D FIX (158 secs)          ││  16    15    032    00      Y   │
│    Longitude Err:   +/- 12 m              ││  18    10    154    00      Y   │
│    Latitude Err:    +/- 6 m               ││  22    21    175    26      N   │
│    Altitude Err:    +/- 17 m              ││  23    75    038    10      N   │
│    Course Err:      n/a                   ││  27    37    068    14      N   │
│    Speed Err:       +/- 87 kph            ││  28    18    231    00      N   │
│    Time offset:     0.727                 ││  30    08    292    00      N   │
│    Grid Square:     MK82sw                ││                                 │
└───────────────────────────────────────────┘└─────────────────────────────────┘

1 Answers1

0

You can use regex:

Ex:

s = """
┌───────────────────────────────────────────┐┌─────────────────────────────────┐
│    Time:       2018-04-10T05:49:46.000Z   ││PRN:   Elev:  Azim:  SNR:  Used: │
│    Latitude:    12.945873 N               ││   1    08    177    23      Y   │
│    Longitude:   77.569187 E               ││   3    35    195    29      Y   │
│    Altitude:   913.1 m                    ││   7    22    313    09      Y   │
│    Speed:      1.2 kph                    ││   8    54    127    24      Y   │
│    Heading:    0.0 deg (true)             ││   9    44    335    25      Y   │
│    Climb:      0.0 m/min                  ││  11    20    168    21      Y   │
│    Status:     3D FIX (158 secs)          ││  16    15    032    00      Y   │
│    Longitude Err:   +/- 12 m              ││  18    10    154    00      Y   │
│    Latitude Err:    +/- 6 m               ││  22    21    175    26      N   │
│    Altitude Err:    +/- 17 m              ││  23    75    038    10      N   │
│    Course Err:      n/a                   ││  27    37    068    14      N   │
│    Speed Err:       +/- 87 kph            ││  28    18    231    00      N   │
│    Time offset:     0.727                 ││  30    08    292    00      N   │
│    Grid Square:     MK82sw                ││                                 │
└───────────────────────────────────────────┘└─────────────────────────────────┘
"""
import re
print re.findall("(?:Longitude:).*(?=E )", s)
print re.findall("(?:Latitude:).*(?=N )", s)

Output:

['Longitude:   77.569187 ']
['Latitude:    12.945873 ']
Rakesh
  • 81,458
  • 17
  • 76
  • 113