[geocode-glib] lib: Add geocode_object_get_coords() function



commit 4c8ab95e5adb969eef3eb6bb503e36c32229bb2c
Author: Bastien Nocera <hadess hadess net>
Date:   Thu May 5 13:21:05 2011 +0100

    lib: Add geocode_object_get_coords() function
    
    To make it easier to parse longitude and latitude from the
    results hashtable.

 geocode-glib/geocode-glib.c       |   39 +++++++++++++++++++++++++++++++++++++
 geocode-glib/geocode-glib.h       |    4 +++
 geocode-glib/geocode-glib.symbols |    1 +
 3 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/geocode-glib/geocode-glib.c b/geocode-glib/geocode-glib.c
index 5078861..298f1a5 100644
--- a/geocode-glib/geocode-glib.c
+++ b/geocode-glib/geocode-glib.c
@@ -526,3 +526,42 @@ geocode_object_resolve (GeocodeObject       *object,
 
 	return ret;
 }
+
+/**
+ * geocode_object_get_coords:
+ * @results: a #GHashTable as generated by geocode_object_resolve()
+ * and geocode_object_resolve_async()
+ * @longitude: a pointer to a #gdouble
+ * @latitude: a pointer to a #gdouble
+ *
+ * Parses the results hashtable and exports the longitude and latitude
+ * as #gdoubles.
+ *
+ * Returns: %TRUE when the longitude and latitude have been
+ * found and the return parameters set.
+ **/
+gboolean
+geocode_object_get_coords (GHashTable *results,
+			   gdouble    *longitude,
+			   gdouble    *latitude)
+{
+	const char *s;
+	gboolean ret = TRUE;
+
+	g_return_val_if_fail (results != NULL, FALSE);
+
+	s = g_hash_table_lookup (results, "longitude");
+	if (s == NULL)
+		ret = FALSE;
+	else if (longitude)
+		*longitude = g_strtod (s, NULL);
+
+	s = g_hash_table_lookup (results, "latitude");
+	if (s == NULL)
+		ret = FALSE;
+	else if (latitude)
+		 *latitude = g_strtod (s, NULL);
+
+	return ret;
+}
+
diff --git a/geocode-glib/geocode-glib.h b/geocode-glib/geocode-glib.h
index e65be8d..f6a3aca 100644
--- a/geocode-glib/geocode-glib.h
+++ b/geocode-glib/geocode-glib.h
@@ -71,6 +71,10 @@ GHashTable *geocode_object_resolve_finish (GeocodeObject  *object,
 GHashTable * geocode_object_resolve (GeocodeObject  *object,
 				     GError        **error);
 
+gboolean geocode_object_get_coords (GHashTable *results,
+				    gdouble    *longitude,
+				    gdouble    *latitude);
+
 G_END_DECLS
 
 #endif /* GEOCODE_GLIB_H */
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 49c4380..3df61d6 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -7,4 +7,5 @@ geocode_object_add
 geocode_object_resolve_async
 geocode_object_resolve_finish
 geocode_object_resolve
+geocode_object_get_coords
 _geocode_parse_json



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