[geocode-glib] reverse: Fix type of lat/lon parameters to backend reverse query method



commit c1042732b927753f6b26ca72bbde3656b860fccd
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Nov 17 17:08:42 2016 +0000

    reverse: Fix type of lat/lon parameters to backend reverse query method
    
    The backend methods are documented as taking parameters which follow the
    Telepathy Location mapping
    (https://telepathy.freedesktop.org/spec/Connection_Interface_Location.html#Mapping:Location),
    or alternatively XEP-0080.
    
    Both of these specify that the ‘lat’ and ‘lon’ parameters are numeric,
    not numeric strings. Since the GeocodeBackend interface has not been
    released yet, fix the implementation to use a GValue holding a gdouble,
    rather than a GValue holding a string representation of a double.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774631

 geocode-glib/geocode-nominatim.c |   11 +++++++++--
 geocode-glib/geocode-reverse.c   |   21 +++++++--------------
 2 files changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/geocode-glib/geocode-nominatim.c b/geocode-glib/geocode-nominatim.c
index 47e2692..2769ed9 100644
--- a/geocode-glib/geocode-nominatim.c
+++ b/geocode-glib/geocode-nominatim.c
@@ -794,6 +794,8 @@ get_resolve_uri_for_params (GeocodeNominatim  *self,
        char *params, *uri;
        GeocodeNominatimPrivate *priv;
        const GValue *lat, *lon;
+       char lat_str[G_ASCII_DTOSTR_BUF_SIZE];
+       char lon_str[G_ASCII_DTOSTR_BUF_SIZE];
 
        priv = geocode_nominatim_get_instance_private (self);
 
@@ -810,8 +812,13 @@ get_resolve_uri_for_params (GeocodeNominatim  *self,
 
        ht = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
 
-       g_hash_table_insert (ht, (gpointer) "lat", (gpointer) g_value_get_string (lat));
-       g_hash_table_insert (ht, (gpointer) "lon", (gpointer) g_value_get_string (lon));
+       g_ascii_dtostr (lat_str, G_ASCII_DTOSTR_BUF_SIZE,
+                       g_value_get_double (lat));
+       g_ascii_dtostr (lon_str, G_ASCII_DTOSTR_BUF_SIZE,
+                       g_value_get_double (lon));
+
+       g_hash_table_insert (ht, (gpointer) "lat", lat_str);
+       g_hash_table_insert (ht, (gpointer) "lon", lon_str);
 
        g_hash_table_insert (ht, (gpointer) "format", (gpointer) "json");
        g_hash_table_insert (ht, (gpointer) "email",
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 27455d7..857f78b 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -110,13 +110,13 @@ ensure_backend (GeocodeReverse *object)
 }
 
 static GValue *
-str_to_value (const gchar *str)
+double_to_value (gdouble val)
 {
        GValue *value;
 
        value = g_new0 (GValue, 1);
-       g_value_init (value, G_TYPE_STRING);
-       g_value_set_string (value, str);
+       g_value_init (value, G_TYPE_DOUBLE);
+       g_value_set_double (value, val);
 
        return value;
 }
@@ -132,21 +132,14 @@ static GHashTable *
 _geocode_location_to_params (GeocodeLocation *location)
 {
        GHashTable *ht;
-       char lat[G_ASCII_DTOSTR_BUF_SIZE];
-       char lon[G_ASCII_DTOSTR_BUF_SIZE];
-
-       g_ascii_dtostr (lat,
-                       G_ASCII_DTOSTR_BUF_SIZE,
-                       geocode_location_get_latitude (location));
-       g_ascii_dtostr (lon,
-                       G_ASCII_DTOSTR_BUF_SIZE,
-                       geocode_location_get_longitude (location));
 
        /* Semantics from http://xmpp.org/extensions/xep-0080.html */
        ht = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
                                    (GDestroyNotify) free_value);
-       g_hash_table_insert (ht, (gpointer) "lat", str_to_value (lat));
-       g_hash_table_insert (ht, (gpointer) "lon", str_to_value (lon));
+       g_hash_table_insert (ht, (gpointer) "lat",
+                            double_to_value (geocode_location_get_latitude (location)));
+       g_hash_table_insert (ht, (gpointer) "lon",
+                            double_to_value (geocode_location_get_longitude (location)));
 
        return ht;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]