addc5b8
From fea6f1844d2c8dc13f94da5af1aea10430ad8ede Mon Sep 17 00:00:00 2001
addc5b8
From: Fabrice Bellet <fabrice@bellet.info>
addc5b8
Date: Wed, 25 Mar 2015 14:52:30 +0100
addc5b8
Subject: [PATCH 3/7] modem-gps: Fix GPS coordinates parsing
addc5b8
addc5b8
Latitude and longitude don't have the same number of digits
addc5b8
on the left side of the decimal point in the GGA NMEA sentence.
addc5b8
addc5b8
https://bugs.freedesktop.org/show_bug.cgi?id=89715
addc5b8
---
addc5b8
 src/gclue-modem-gps.c | 11 +++++++++--
addc5b8
 1 file changed, 9 insertions(+), 2 deletions(-)
addc5b8
addc5b8
diff --git a/src/gclue-modem-gps.c b/src/gclue-modem-gps.c
addc5b8
index 7f1338f..5295fe3 100644
addc5b8
--- a/src/gclue-modem-gps.c
addc5b8
+++ b/src/gclue-modem-gps.c
addc5b8
@@ -215,6 +215,8 @@ parse_coordinate_string (const char *coordinate,
addc5b8
 {
addc5b8
         gdouble minutes, degrees, out;
addc5b8
         gchar *degrees_str;
addc5b8
+        gchar *dot_str;
addc5b8
+        gint dot_offset;
addc5b8
 
addc5b8
         if (coordinate[0] == '\0' ||
addc5b8
             direction[0] == '\0' ||
addc5b8
@@ -230,11 +232,16 @@ parse_coordinate_string (const char *coordinate,
addc5b8
                 return INVALID_COORDINATE;
addc5b8
         }
addc5b8
 
addc5b8
-        degrees_str = g_strndup (coordinate, 2);
addc5b8
+        dot_str = g_strstr_len (coordinate, 6, ".");
addc5b8
+        if (dot_str == NULL)
addc5b8
+                return INVALID_COORDINATE;
addc5b8
+        dot_offset = dot_str - coordinate;
addc5b8
+
addc5b8
+        degrees_str = g_strndup (coordinate, dot_offset - 2);
addc5b8
         degrees = g_ascii_strtod (degrees_str, NULL);
addc5b8
         g_free (degrees_str);
addc5b8
 
addc5b8
-        minutes = g_ascii_strtod (coordinate + 2, NULL);
addc5b8
+        minutes = g_ascii_strtod (coordinate + dot_offset - 2, NULL);
addc5b8
 
addc5b8
         /* Include the minutes as part of the degrees */
addc5b8
         out = degrees + (minutes / 60.0);
addc5b8
-- 
addc5b8
2.1.0
addc5b8