[gnome-maps/wip/contacts] wipwip



commit d7658b1c0dc1e4dbc53df5a72ab0c4d9e52900bf
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Wed Dec 10 07:00:39 2014 -0500

    wipwip

 lib/mapsc-contacts.c  |    4 ++--
 src/application.js    |   36 ++++++++++++++++++++++--------------
 src/geocodeService.js |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 16 deletions(-)
---
diff --git a/lib/mapsc-contacts.c b/lib/mapsc-contacts.c
index 844ae0e..7bc8d6a 100644
--- a/lib/mapsc-contacts.c
+++ b/lib/mapsc-contacts.c
@@ -146,8 +146,8 @@ get_contact (FolksIndividual *individual)
     details = gee_iterator_get (iter);
     address = (FolksPostalAddress *) folks_abstract_field_details_get_value (details);
 
-    g_object_get (G_OBJECT (address), "id", &id);
-
+    g_print ("id: %s\n", folks_abstract_field_details_get_id (details));
+    
     values = gee_multi_map_get_values (folks_abstract_field_details_get_parameters (details));
     values_iter = gee_iterable_iterator (GEE_ITERABLE (values));
     if (!values_iter)
diff --git a/src/application.js b/src/application.js
index decc8bb..5dfa40e 100644
--- a/src/application.js
+++ b/src/application.js
@@ -106,22 +106,30 @@ const Application = new Lang.Class({
         this._checkNetwork();
         this._mainWindow.window.present();
 
+        log (parameter.deep_unpack());
+
         let contactArray = [];
         contacts.lookup(parameter.deep_unpack(), (function(contact) {
-            contact.get_addresses().forEach(function(address) {
-                contactArray.push(new Contact.Contact({ name: contact.name,
-                                                        id: contact.id,
-                                                        icon: contact.icon,
-                                                        type: address.type,
-                                                        street_address: address.street,
-                                                        county: address.region,
-                                                        town: address.locality,
-                                                        postal_code: address.postal_code,
-                                                        country: address.country
-                                                      }));
-            });
-
-            this._mainWindow.mapView.showContact(contactArray);
+            let addresses = contact.get_addresses();
+            geocodeService.searchAddresses (addresses, (function (locations) {
+                addresses.forEach(function(address) {
+                    let location = locations[address.street];
+                    if (!location)
+                        return;
+                    
+                    contactArray.push(new Contact.Contact({ name: contact.name,
+                                                            id: contact.id,
+                                                            icon: contact.icon,
+                                                            type: address.type,
+                                                            street_address: address.street,
+                                                            county: address.region,
+                                                            town: address.locality,
+                                                            postal_code: address.postal_code,
+                                                            country: address.country
+                                                          }));
+                });
+                this._mainWindow.mapView.showContact(contactArray);
+            }).bind(this));
         }).bind(this));
     },
 
diff --git a/src/geocodeService.js b/src/geocodeService.js
index e5e1df1..2151afd 100644
--- a/src/geocodeService.js
+++ b/src/geocodeService.js
@@ -22,6 +22,7 @@
  */
 
 const Geocode = imports.gi.GeocodeGlib;
+const GObject = imports.gi.GObject;
 const Lang = imports.lang;
 
 const Application = imports.application;
@@ -32,6 +33,48 @@ const GeocodeService = new Lang.Class({
 
     _init: function() { },
 
+    searchAddresses: function(addresses, callback) {
+        let locations = {};
+        let geocodes = 0;
+        
+        addresses.forEach(function(address) {
+            let streetValue = new GObject.Value();
+            streetValue.init(GObject.TYPE_STRING);
+            streetValue.set_string(address.street);
+
+            let localityValue = new GObject.Value();
+            localityValue.init(GObject.TYPE_STRING);
+            localityValue.set_string(address.locality);
+
+            let countyValue = new GObject.Value();
+            countyValue.init(GObject.TYPE_STRING);
+            countyValue.set_string(address.region);
+
+            let countryValue = new GObject.Value();
+            countryValue.init(GObject.TYPE_STRING);
+            countryValue.set_string(address.country);
+
+            const param = {
+                street: streetValue,
+                locality: localityValue,
+                county: countyValue,
+                country: countryValue
+            };
+            
+            let forward = Geocode.Forward.new_for_params(param);
+            forward.search_async(null, function(forward, res) {
+                let places = forward.search_finish(res);
+
+                if (places && places.length > 0)
+                    locations[address.street] = places[0].location;
+
+                geocodes++;
+                if (geocodes === addresses.length)
+                    callback(locations);
+            });
+        });
+    },
+    
     search: function(string, bbox, callback) {
         let answerCount = Application.settings.get('max-search-results');
         let forward     = Geocode.Forward.new_for_string(string);


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