You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/08/17 20:54:50 UTC

[4/19] js commit: Added geolocation.js

Added geolocation.js


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/4779732d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/4779732d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/4779732d

Branch: refs/heads/master
Commit: 4779732dcaeb02e8a0bc7cb233e6b32f52b6e939
Parents: 0a51b06
Author: mpberk <ma...@intel.com>
Authored: Fri Aug 17 10:44:27 2012 -0700
Committer: mpberk <ma...@intel.com>
Committed: Fri Aug 17 10:44:27 2012 -0700

----------------------------------------------------------------------
 lib/win8metro/platform.js                     |   13 ++-
 lib/win8metro/plugin/win8metro/geolocation.js |   89 ++++++++++++++++++++
 2 files changed, 97 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4779732d/lib/win8metro/platform.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/platform.js b/lib/win8metro/platform.js
index 395059a..70933e1 100755
--- a/lib/win8metro/platform.js
+++ b/lib/win8metro/platform.js
@@ -38,10 +38,7 @@ module.exports = {
                 console: {
                     path: "cordova/plugin/win8metro/console"
 
-                }/*,
-                notification: {
-                    path: 'cordova/plugin/notification'
-                }*/
+                }
             }
 
         }
@@ -58,7 +55,13 @@ module.exports = {
     merges: {
         MediaFile: {
             path: "cordova/plugin/win8metro/MediaFile"
+        },
+        navigator: {
+            children: {
+                notification: {
+                    path: 'cordova/plugin/win8metro/geolocation'
+                }
+            }
         }
-
     }
 };
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4779732d/lib/win8metro/plugin/win8metro/geolocation.js
----------------------------------------------------------------------
diff --git a/lib/win8metro/plugin/win8metro/geolocation.js b/lib/win8metro/plugin/win8metro/geolocation.js
new file mode 100644
index 0000000..434dcf9
--- /dev/null
+++ b/lib/win8metro/plugin/win8metro/geolocation.js
@@ -0,0 +1,89 @@
+var Position = require('cordova/plugin/Position'),
+    PositionError = require('cordova/plugin/PositionError');
+
+module.exports = { // Merges with common
+
+
+    getLocation:function(win, lose, args) {
+        // options.enableHighAccuracy
+        // options.maximumAge
+        // options.timeout
+
+        var geolocator = new Windows.Devices.Geolocation.Geolocator();
+        if (options.enableHighAccuracy) {
+            geolocator.desiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.high;
+        }
+
+        geolocator.getGeopositionAsync(options.maximumAge, options.timeout).done(
+            function(geoposition) {
+                // Win8 JS API coordinate Object
+                win(geoposition.coordinate);
+            }, function() {
+                var e = new Object();
+
+                switch (geolocator.locationStatus) {
+                    case Windows.Devices.Geolocation.PositionStatus.ready:
+                        // Location data is available
+                        e.message = "Location is available.";
+                        e.code = PositionError.TIMEOUT;
+                        lose (e);
+                        break;
+                    case Windows.Devices.Geolocation.PositionStatus.initializing:
+                        // This status indicates that a GPS is still acquiring a fix
+                        e.message = "A GPS device is still initializing.";
+                        e.code = PositionError.POSITION_UNAVAILABLE;
+                        lose(e);
+                        break;
+                    case Windows.Devices.Geolocation.PositionStatus.noData:
+                        // No location data is currently available
+                        e.message = "Data from location services is currently unavailable.";
+                        e.code = PositionError.POSITION_UNAVAILABLE;
+                        lose(e);
+                        break;
+                    case Windows.Devices.Geolocation.PositionStatus.disabled:
+                        // The app doesn't have permission to access location,
+                        // either because location has been turned off.
+                        e.message = "Your location is currently turned off. " +
+                        "Change your settings through the Settings charm " +
+                        " to turn it back on.";
+                        e.code = PositionError.PERMISSION_DENIED;
+                        lose(e);
+                        break;
+                    case Windows.Devices.Geolocation.PositionStatus.notInitialized:
+                        // This status indicates that the app has not yet requested
+                        // location data by calling GetGeolocationAsync() or
+                        // registering an event handler for the positionChanged event.
+                        e.message = "Location status is not initialized because " +
+                        "the app has not requested location data.";
+                        e.code = PositionError.POSITION_UNAVAILABLE;
+                        lose(e);
+                        break;
+                    case Windows.Devices.Geolocation.PositionStatus.notAvailable:
+                        // Location is not available on this version of Windows
+                        e.message = "You do not have the required location services " +
+                        "present on your system.";
+                        e.code = PositionError.POSITION_UNAVAILABLE;
+                        lose(e);
+                        break;
+                    default:
+                        e.code = PositionError.TIMEOUT;
+                        lose(e);
+                        break;
+
+                }
+            }
+        )
+    },
+
+    addWatch:function(win, lose, args) {
+        // id
+        // options
+        // options.maximumAge
+        // options.timeout
+        // timers[]
+        timers[id] = new Windows.Devices.Geolocation.Geolocator().getGeopositionAsync(options.maximumAge, options.timeout).done(
+            new Geolocation().getCurrentPosition(win, lose, options)
+        )
+    }
+    // clearWatch is not needed as in common code the timer is deleted
+};
\ No newline at end of file