Knio / pynmea2

Python library for parsing the NMEA 0183 protocol (GPS)
MIT License
628 stars 223 forks source link

GGA sentence latiitude and longitude are parsed incorrectly #135

Closed camielverdult closed 3 years ago

camielverdult commented 3 years ago

The following code parses a GGA message:

Python 3.9.4 (default, Apr  6 2021, 15:29:50) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynmea2
>>> gga = pynmea2.parse("$GPGGA,123037.00,5213.55195,N,00641.61109,E,1,12,0.87,9.6,M,46.0,M,,*5D")
>>> gga
<GGA(timestamp=datetime.time(12, 30, 37), lat='5213.55195', lat_dir='N', lon='00641.61109', lon_dir='E', gps_qual=1, num_sats='12', horizontal_dil='0.87', altitude=9.6, altitude_units='M', geo_sep='46.0', geo_sep_units='M', age_gps_data='', ref_station_id='')>

When wanting to access the latitude and longitude property, the following values are returned:

>>> gga.lat
'5213.55195'
>>> gga.lon
'00641.61109'

These values are of factor 100 too big...

camielverdult commented 3 years ago

Nvm, sorry

camielverdult commented 3 years ago

Here is code that converts the NMEA latitude and longitude to decimal degrees. I found how to convert in the Readme, I was very confused first...

    def get_geo_coordinates(GGA_data: pynmea2.GGA) -> tuple:
        latitude = '%02d°%02d′%07.4f″' % (GGA_data.latitude, GGA_data.latitude_minutes, GGA_data.latitude_seconds)

        longitude = '%02d°%02d′%07.4f″' % (GGA_data.longitude, GGA_data.longitude_minutes, GGA_data.longitude_seconds)

        return (latitude, longitude)