[gnome-contacts/wip/map-widget: 4/7] contacts-contact: Add method to geocode a contact
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/wip/map-widget: 4/7] contacts-contact: Add method to geocode a contact
- Date: Wed, 17 Dec 2014 06:35:15 +0000 (UTC)
commit 697be63f782847ce1dd7381ecec398293d1a636b
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Tue Dec 16 05:32:17 2014 -0500
contacts-contact: Add method to geocode a contact
https://bugzilla.gnome.org/show_bug.cgi?id=658553
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]