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