[gnome-maps] Move reverse geocoding to GeocodeService



commit be6031b65cb45bdd362338ef5ef59ff152fbae31
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Fri Sep 12 21:03:51 2014 +0200

    Move reverse geocoding to GeocodeService
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736572

 src/contextMenu.js    |   24 +++---------------------
 src/geocodeService.js |   20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 21 deletions(-)
---
diff --git a/src/contextMenu.js b/src/contextMenu.js
index d6e573b..0c1c887 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -64,7 +64,7 @@ const ContextMenu = new Lang.Class({
                                               longitude: this._longitude,
                                               accuracy: 0 });
 
-        this._reverseGeocode(location, (function(place) {
+        Application.geocodeService.reverse(location, (function(place) {
             this._mapView.showSearchResult(place);
         }).bind(this));
     },
@@ -74,29 +74,11 @@ const ContextMenu = new Lang.Class({
                                               longitude: this._longitude,
                                               accuracy: 0,
                                               description: "" });
-        this._reverseGeocode(location, (function(place) {
+
+        Application.geocodeService.reverse(location, (function(place) {
             location.description = place.name;
             Application.geoclue.overrideLocation(location);
         }).bind(this));
-    },
-
-    _reverseGeocode: function(location, resultCallback) {
-        let reverse = Geocode.Reverse.new_for_location(location);
-
-        Application.application.mark_busy();
-        reverse.resolve_async (null, (function(reverse, res) {
-            Application.application.unmark_busy();
-            try {
-                let place = reverse.resolve_finish(res);
-
-                resultCallback(place);
-            } catch (e) {
-                log ("Error finding place at " +
-                     this._latitude + ", " +
-                     this._longitude + ": " +
-                     e.message);
-            }
-        }).bind(this));
     }
 });
 Utils.addSignalMethods(ContextMenu.prototype);
diff --git a/src/geocodeService.js b/src/geocodeService.js
index 434afd6..e5e1df1 100644
--- a/src/geocodeService.js
+++ b/src/geocodeService.js
@@ -25,6 +25,7 @@ const Geocode = imports.gi.GeocodeGlib;
 const Lang = imports.lang;
 
 const Application = imports.application;
+const Utils = imports.utils;
 
 const GeocodeService = new Lang.Class({
     Name: 'GeocodeService',
@@ -53,5 +54,24 @@ const GeocodeService = new Lang.Class({
                 callback(null);
             }
         });
+    },
+
+    reverse: function(location, callback) {
+        let reverse = Geocode.Reverse.new_for_location(location);
+
+        Application.application.mark_busy();
+        reverse.resolve_async (null, (function(reverse, res) {
+            Application.application.unmark_busy();
+            try {
+                let place = reverse.resolve_finish(res);
+                callback(place);
+            } catch (e) {
+                Utils.debug("Error finding place at " +
+                            this._latitude + ", " +
+                            this._longitude + ": " +
+                            e.message);
+                callback(null);
+            }
+        }).bind(this));
     }
 });


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