@@ -283,8 +283,8 @@ def _decode_rmc(self, data: str):
283
283
int (time_buf [2 :4 ]),
284
284
int (time_buf [4 :6 ]),
285
285
]
286
- self .latitude = gps_list [3 ] + gps_list [4 ]
287
- self .longitude = gps_list [5 ] + gps_list [6 ]
286
+ self .latitude = self . _convert_to_decimal ( gps_list [3 ], gps_list [4 ])
287
+ self .longitude = self . _convert_to_decimal ( gps_list [5 ], gps_list [6 ], False )
288
288
self .speed_ground_knot = gps_list [7 ]
289
289
self .corse_ground_degree = gps_list [8 ]
290
290
data_buf = gps_list [9 ]
@@ -303,6 +303,33 @@ def _decode_rmc(self, data: str):
303
303
buf = time .mktime (t )
304
304
self .timestamp = buf
305
305
306
+ def _convert_to_decimal (self , degrees_minutes , direction , latitude : bool = True ) -> float :
307
+ """
308
+ note:
309
+ en: Convert latitude or longitude from degrees minutes format to decimal format.
310
+
311
+ params:
312
+ degrees_minutes:
313
+ note: Latitude or Longitude in DDMM.MMMM format (e.g., "2242.10772").
314
+ direction:
315
+ note: Direction of the coordinate ("N", "S", "E", "W").
316
+ latitude:
317
+ note: True if latitude, False if longitude.
318
+
319
+ returns:
320
+ note: The decimal value of the coordinate.
321
+ """
322
+ if latitude :
323
+ degrees = degrees_minutes [:2 ] # First two digits are degrees
324
+ minutes = degrees_minutes [2 :] # The rest are minutes
325
+ else :
326
+ degrees = degrees_minutes [:3 ]
327
+ minutes = degrees_minutes [3 :]
328
+ decimal = int (degrees ) + round (float (minutes ) / 60.0 , 6 )
329
+ if direction in ["S" , "W" ]:
330
+ decimal = - decimal
331
+ return decimal
332
+
306
333
def _decode_txt (self , data : str ):
307
334
"""
308
335
note:
0 commit comments