[geocode-glib/wip/reverse-ret-place: 2/6] lib: One dedicated function to create GeocodePlace object



commit 8ba11adbd8b1e2259f7754b36a4afa57c82c4dc6
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Jul 29 23:26:30 2013 +0300

    lib: One dedicated function to create GeocodePlace object
    
    We already have a function to create the GeocodePlace instance from
    Nominatim attributes, create_place_from_attributes(). We should
    initialize all props of these instances from within that function,
    rather than doing it soon after calling it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705112

 geocode-glib/geocode-forward.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index e3d812d..51325e4 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -626,8 +626,10 @@ static GeocodePlace *
 create_place_from_attributes (GHashTable *ht)
 {
         GeocodePlace *place;
+        GeocodeLocation *loc = NULL;
         const char *name, *street, *building;
         GeocodePlaceType place_type;
+        gdouble longitude, latitude;
 
         place_type = get_place_type_from_attributes (ht);
 
@@ -648,6 +650,20 @@ create_place_from_attributes (GHashTable *ht)
             g_free (address);
         }
 
+        g_hash_table_foreach (ht, (GHFunc) fill_place_from_entry, place);
+
+        /* Get latitude and longitude and create GeocodeLocation object. */
+        longitude = g_ascii_strtod (g_hash_table_lookup (ht, "lon"), NULL);
+        latitude = g_ascii_strtod (g_hash_table_lookup (ht, "lat"), NULL);
+        name = geocode_place_get_name (place);
+
+        loc = geocode_location_new_with_description (latitude,
+                                                     longitude,
+                                                     GEOCODE_LOCATION_ACCURACY_UNKNOWN,
+                                                     name);
+        geocode_place_set_location (place, loc);
+        g_object_unref (loc);
+
         return place;
 }
 
@@ -656,10 +672,7 @@ insert_place_into_tree (GNode *place_tree, GHashTable *ht)
 {
        GNode *start = place_tree, *child = NULL;
         GeocodePlace *place = NULL;
-       GeocodeLocation *loc = NULL;
        char *attr_val = NULL;
-       const char *name;
-       gdouble longitude, latitude;
        guint i;
 
        for (i = 0; i < G_N_ELEMENTS(attributes); i++) {
@@ -687,22 +700,8 @@ insert_place_into_tree (GNode *place_tree, GHashTable *ht)
 
         place = create_place_from_attributes (ht);
 
-        g_hash_table_foreach (ht, (GHFunc) fill_place_from_entry, place);
-
-       /* Get latitude and longitude and create GeocodeLocation object.
-        * The leaf node of the tree is the GeocodePlace object, containing
-         * associated GeocodeLocation object */
-       longitude = g_ascii_strtod (g_hash_table_lookup (ht, "lon"), NULL);
-       latitude = g_ascii_strtod (g_hash_table_lookup (ht, "lat"), NULL);
-        name = geocode_place_get_name (place);
-
-       loc = geocode_location_new_with_description (latitude,
-                                                 longitude,
-                                                 GEOCODE_LOCATION_ACCURACY_UNKNOWN,
-                                                 name);
-        geocode_place_set_location (place, loc);
-        g_object_unref (loc);
-
+        /* The leaf node of the tree is the GeocodePlace object, containing
+         * associated GeocodePlace object */
        g_node_insert_data (start, -1, place);
 }
 


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