From d4cf232683afe9e66e7db1765fa5cc7f9414a3f1 Mon Sep 17 00:00:00 2001 From: Tetsuhiko NAGAHARA Date: Wed, 18 Jan 2023 17:12:49 +0900 Subject: [PATCH] Fix for issue #27 Changes in dd location format. --- micropyGPS.py | 12 +++++++----- test_micropyGPS.py | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/micropyGPS.py b/micropyGPS.py index 61b19ed..af826cb 100644 --- a/micropyGPS.py +++ b/micropyGPS.py @@ -45,7 +45,7 @@ class MicropyGPS(object): location_formatting (str): Style For Presenting Longitude/Latitude: Decimal Degree Minute (ddm) - 40° 26.767′ N Degrees Minutes Seconds (dms) - 40° 26′ 46″ N - Decimal Degrees (dd) - 40.446° N + Decimal Degrees (dd) - 40.446° """ ##################### @@ -107,7 +107,8 @@ class MicropyGPS(object): """Format Latitude Data Correctly""" if self.coord_format == 'dd': decimal_degrees = self._latitude[0] + (self._latitude[1] / 60) - return [decimal_degrees, self._latitude[2]] + sign_dd = (self._latitude[2] == 'N') - (self._latitude[2] == 'S') + return sign_dd * decimal_degrees elif self.coord_format == 'dms': minute_parts = modf(self._latitude[1]) seconds = round(minute_parts[0] * 60) @@ -120,7 +121,8 @@ class MicropyGPS(object): """Format Longitude Data Correctly""" if self.coord_format == 'dd': decimal_degrees = self._longitude[0] + (self._longitude[1] / 60) - return [decimal_degrees, self._longitude[2]] + sign_dd = (self._longitude[2] == 'E') - (self._longitude[2] == 'W') + return sign_dd * decimal_degrees elif self.coord_format == 'dms': minute_parts = modf(self._longitude[1]) seconds = round(minute_parts[0] * 60) @@ -709,7 +711,7 @@ class MicropyGPS(object): """ if self.coord_format == 'dd': formatted_latitude = self.latitude - lat_string = str(formatted_latitude[0]) + '° ' + str(self._latitude[2]) + lat_string = str(formatted_latitude) + '°' elif self.coord_format == 'dms': formatted_latitude = self.latitude lat_string = str(formatted_latitude[0]) + '° ' + str(formatted_latitude[1]) + "' " + str(formatted_latitude[2]) + '" ' + str(formatted_latitude[3]) @@ -724,7 +726,7 @@ class MicropyGPS(object): """ if self.coord_format == 'dd': formatted_longitude = self.longitude - lon_string = str(formatted_longitude[0]) + '° ' + str(self._longitude[2]) + lon_string = str(formatted_longitude) + '°' elif self.coord_format == 'dms': formatted_longitude = self.longitude lon_string = str(formatted_longitude[0]) + '° ' + str(formatted_longitude[1]) + "' " + str(formatted_longitude[2]) + '" ' + str(formatted_longitude[3]) diff --git a/test_micropyGPS.py b/test_micropyGPS.py index a97eb21..464b08e 100644 --- a/test_micropyGPS.py +++ b/test_micropyGPS.py @@ -427,9 +427,9 @@ def test_coordinate_representations(): for y in RMC_sentence: my_gps.update(y) print('') - assert my_gps.latitude_string() == '53.361336666666666° N' + assert my_gps.latitude_string() == '53.361336666666666°' print('Decimal Degrees Latitude:', my_gps.latitude_string()) - assert my_gps.longitude_string() == '6.5056183333333335° W' + assert my_gps.longitude_string() == '-6.5056183333333335°' print('Decimal Degrees Longitude:', my_gps.longitude_string()) my_gps.coord_format = 'dms' print('Degrees Minutes Seconds Latitude:', my_gps.latitude_string())