incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [2/3] git commit: Fixing up coords and location specs and implementation
Date Wed, 07 Mar 2012 00:08:09 GMT
Fixing up coords and location specs and implementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/88f8c136
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/88f8c136
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/88f8c136

Branch: refs/heads/master
Commit: 88f8c1367675de87dc14cd8b9611e0bb36db987e
Parents: d599893
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Mar 6 13:03:32 2012 -0800
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Mar 6 16:07:15 2012 -0800

----------------------------------------------------------------------
 lib/plugin/Position.js    |    4 +++-
 lib/plugin/geolocation.js |   33 +++++++++++++++++++++++++++------
 test/test.geolocation.js  |    8 ++++----
 3 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/88f8c136/lib/plugin/Position.js
----------------------------------------------------------------------
diff --git a/lib/plugin/Position.js b/lib/plugin/Position.js
index 7b63e19..25096c4 100644
--- a/lib/plugin/Position.js
+++ b/lib/plugin/Position.js
@@ -1,5 +1,7 @@
+var Coordinates = require('cordova/plugin/Coordinates');
+
 var Position = function(coords, timestamp) {
-	this.coords = coords;
+	this.coords = new Coordinates(coords.latitude, coords.longitude, coords.altitude, coords.accuracy,
coords.heading, coords.velocity, coords.altitudeAccuracy);
 	this.timestamp = (timestamp !== undefined) ? timestamp : new Date().getTime();
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/88f8c136/lib/plugin/geolocation.js
----------------------------------------------------------------------
diff --git a/lib/plugin/geolocation.js b/lib/plugin/geolocation.js
index 93156b1..e1169f6 100644
--- a/lib/plugin/geolocation.js
+++ b/lib/plugin/geolocation.js
@@ -1,6 +1,7 @@
 var utils = require('cordova/utils'),
     exec = require('cordova/exec'),
-    PositionError = require('cordova/plugin/PositionError');
+    PositionError = require('cordova/plugin/PositionError'),
+    Position = require('cordova/plugin/Position');
 
 var timers = {};   // list of timers in use
 
@@ -13,13 +14,13 @@ function parseParameters(options) {
     };
 
     if (options) {
-        if (typeof options.maximumAge !== "undefined") {
+        if (options.maximumAge !== undefined) {
             opt.maximumAge = options.maximumAge;
         }
-        if (typeof options.enableHighAccuracy !== "undefined") {
+        if (options.enableHighAccuracy !== undefined) {
             opt.enableHighAccuracy = options.enableHighAccuracy;
         }
-        if (typeof options.timeout !== "undefined") {
+        if (options.timeout !== undefined) {
             opt.timeout = options.timeout;
         }
     }
@@ -37,7 +38,26 @@ var geolocation = {
    */
     getCurrentPosition:function(successCallback, errorCallback, options) {
         options = parseParameters(options);
-        exec(successCallback, errorCallback, "Geolocation", "getLocation", [options.enableHighAccuracy,
options.timeout, options.maximumAge]); 
+
+        var win = function(p) {
+            successCallback(new Position(
+                {
+                    latitude:p.latitude,
+                    longitude:p.longitude,
+                    altitude:p.altitude,
+                    accuracy:p.accuracy,
+                    heading:p.heading,
+                    velocity:p.velocity,
+                    altitudeAccuracy:p.altitudeAccuracy
+                },
+                p.timestamp || new Date()
+            ));
+        };
+        var fail = function(e) {
+            errorCallback(new PositionError(e.code, e.message));
+        };
+
+        exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout,
options.maximumAge]); 
     },
     /**
      * Asynchronously watches the geolocation for changes to geolocation.  When a change
occurs,
@@ -50,9 +70,10 @@ var geolocation = {
      */
     watchPosition:function(successCallback, errorCallback, options) {
         options = parseParameters(options);
+
         var id = utils.createUUID();
         timers[id] = window.setInterval(function() {
-            exec(successCallback, errorCallback, "Geolocation", "getLocation", [options.enableHighAccuracy,
options.timeout, options.maximumAge]);
+            geolocation.getCurrentPosition(successCallback, errorCallback, options);
         }, options.timeout);
 
         return id;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/88f8c136/test/test.geolocation.js
----------------------------------------------------------------------
diff --git a/test/test.geolocation.js b/test/test.geolocation.js
index fe6c323..a24059c 100644
--- a/test/test.geolocation.js
+++ b/test/test.geolocation.js
@@ -11,22 +11,22 @@ describe("geolocation", function () {
     describe("when getting the current position", function () {
         it("uses the default values", function () {
             geo.getCurrentPosition(s, e);
-            expect(exec).toHaveBeenCalledWith(s, e, "Geolocation", "getLocation", [false,
10000, 10000]);
+            expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function),
"Geolocation", "getLocation", [false, 10000, 10000]);
         });
 
         it("uses the maximumAge option", function () {
             geo.getCurrentPosition(s, e, {maximumAge: 10});
-            expect(exec).toHaveBeenCalledWith(s, e, "Geolocation", "getLocation", [false,
10000, 10]);
+            expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function),
"Geolocation", "getLocation", [false, 10000, 10]);
         });
 
         it("uses the enableHighAccuracy option", function () {
             geo.getCurrentPosition(s, e, {enableHighAccuracy: true, maximumAge: 100});
-            expect(exec).toHaveBeenCalledWith(s, e, "Geolocation", "getLocation", [true,
10000, 100]);
+            expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function),
"Geolocation", "getLocation", [true, 10000, 100]);
         });
 
         it("uses the timeout option", function () {
             geo.getCurrentPosition(s, e, {timeout: 1000});
-            expect(exec).toHaveBeenCalledWith(s, e, "Geolocation", "getLocation", [false,
1000, 10000]);
+            expect(exec).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function),
"Geolocation", "getLocation", [false, 1000, 10000]);
         });
     });
 


Mime
View raw message