[gnome-contacts/wip/map-widget: 4/5] contacts-contact: Add method to geocode a contact



commit df52f5736bd552588e05e41e68a25952c1e2276a
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Dec 16 05:32:17 2014 -0500

    contacts-contact: Add method to geocode a contact

 configure.ac              |    3 ++-
 src/contacts-contact.vala |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a7702fa..7ad72f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,10 +50,11 @@ pkg_modules="gtk+-3.0 >= 3.12.0
             libedataserver-1.2 >= 3.5.3
             goa-1.0
             gee-0.8
+            geocode-glib-1.0
             "
 PKG_CHECK_MODULES(CONTACTS, [$pkg_modules])
 
-CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg gio-unix-2.0 --pkg folks --pkg folks-telepathy --pkg 
folks-eds --pkg libnotify"
+CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg gio-unix-2.0 --pkg folks --pkg folks-telepathy --pkg 
folks-eds --pkg libnotify --pkg geocode-glib-1.0"
 AC_SUBST(CONTACTS_PACKAGES)
 
 # Optional dependency for the user accounts panel
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index b3c14da..4078a75 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -20,6 +20,7 @@ using Gtk;
 using Folks;
 using Gee;
 using TelepathyGLib;
+using Geocode;
 
 public errordomain ContactError {
   NOT_IMPLEMENTED,
@@ -672,6 +673,39 @@ public class Contacts.Contact : GLib.Object  {
     return res;
   }
 
+  public static async Place geocode_address (PostalAddress addr) {
+    SourceFunc callback = geocode_address.callback;
+    var params = new HashTable<string, GLib.Value?>(str_hash, str_equal);
+
+    if (is_set (addr.street))
+      params.insert("street", addr.street);
+
+    if (is_set (addr.locality))
+      params.insert("locality", addr.locality);
+
+    if (is_set (addr.region))
+      params.insert("region", addr.region);
+
+    if (is_set (addr.country))
+      params.insert("country", addr.country);
+
+    Place? place = null;
+    var forward = new Forward.for_params (params);
+    forward.search_async.begin (null, (object, res) => {
+        try {
+          var places = forward.search_async.end (res);
+
+          place = places.nth_data (0);
+          callback ();
+        } catch (GLib.Error e) {
+          debug ("No geocode result found for contact");
+          callback ();
+        }
+      });
+    yield;
+    return place;
+  }
+
   public static string[] format_address (PostalAddress addr) {
     string[] lines = {};
 


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