cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [08/14] git commit: CB-5114 Windows 8.1 - Use a new proxy as old geolocation methods is deprecated
Date Thu, 07 Aug 2014 20:22:51 GMT
CB-5114 Windows 8.1 - Use a new proxy as old geolocation methods is deprecated

* Added separate section for Windows Univeral Apps
* Made GeolocationProxy compatible with windows8.0 and 8.1 api versions


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/commit/4137f9dd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/4137f9dd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/4137f9dd

Branch: refs/heads/master
Commit: 4137f9dd4c83c118912a582a3bb414c1167ed6cb
Parents: e9eaa78
Author: sgrebnov <v-segreb@microsoft.com>
Authored: Fri Jul 11 17:52:03 2014 +0400
Committer: sgrebnov <v-segreb@microsoft.com>
Committed: Fri Jul 11 17:52:03 2014 +0400

----------------------------------------------------------------------
 plugin.xml                        |  53 ++++++++---
 src/windows/GeolocationProxy.js   | 166 +++++++++++++++++++++++++++++++++
 src/windows8/GeolocationProxy.js  | 157 -------------------------------
 src/windows81/GeolocationProxy.js | 157 -------------------------------
 4 files changed, 208 insertions(+), 325 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/4137f9dd/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 5996fbe..d4b3b89 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -191,24 +191,55 @@ xmlns:android="http://schemas.android.com/apk/res/android"
         <config-file target="package.appxmanifest" parent="/Package/Capabilities">
             <DeviceCapability Name="location" />
         </config-file>
+
+        <js-module src="src/windows/GeolocationProxy.js" name="GeolocationProxy">
+            <runs />
+        </js-module>
+
+        <js-module src="www/Coordinates.js" name="Coordinates">
+            <clobbers target="Coordinates" />
+        </js-module>
+
         <js-module src="www/PositionError.js" name="PositionError">
             <clobbers target="PositionError" />
         </js-module>
-        <js-module src="src/windows8/GeolocationProxy.js" name="GeolocationProxy">
-          <merges target="" />
+
+        <js-module src="www/Position.js" name="Position">
+            <clobbers target="Position" />
+        </js-module>
+
+        <js-module src="www/geolocation.js" name="geolocation">
+            <clobbers target="navigator.geolocation" />
         </js-module>
     </platform>
 
-    <!-- windows81 -->
-    <platform name="windows81">
-      <config-file target="package.appxmanifest" parent="/Package/Capabilities">
-        <DeviceCapability Name="location" />
-      </config-file>
-      <js-module src="src/windows81/GeolocationProxy.js" name="GeolocationProxy">
-        <merges target="" />
-      </js-module>
-    </platform>
+    <!-- windows universal apps (Windows 8.1, Windows Phone 8.1, Windows 8.0) -->
+    <platform name="windows">
+        <config-file target="package.appxmanifest" parent="/Package/Capabilities">
+            <DeviceCapability Name="location" />
+        </config-file>
 
+        <js-module src="src/windows/GeolocationProxy.js" name="GeolocationProxy">
+            <runs />
+        </js-module>
+
+        <js-module src="www/Coordinates.js" name="Coordinates">
+            <clobbers target="Coordinates" />
+        </js-module>
+
+        <js-module src="www/PositionError.js" name="PositionError">
+            <clobbers target="PositionError" />
+        </js-module>
+
+        <js-module src="www/Position.js" name="Position">
+            <clobbers target="Position" />
+        </js-module>
+
+        <js-module src="www/geolocation.js" name="geolocation">
+            <clobbers target="navigator.geolocation" />
+        </js-module>
+    </platform>
+    
     <!-- firefoxos -->
     <platform name="firefoxos">
       <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/4137f9dd/src/windows/GeolocationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js
new file mode 100644
index 0000000..bafff6d
--- /dev/null
+++ b/src/windows/GeolocationProxy.js
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2013 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var PositionError = require('./PositionError'),
+    ids = {},
+    loc;
+
+function ensureLocator() {
+    if (loc == null)
+        loc = new Windows.Devices.Geolocation.Geolocator();
+
+    return loc;
+}
+
+function createErrorCode() {
+    switch (loc.locationStatus) {
+        case Windows.Devices.Geolocation.PositionStatus.initializing:
+            // This status indicates that a location device is still initializing
+        case Windows.Devices.Geolocation.PositionStatus.noData:
+            // No location data is currently available 
+        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. 
+        case Windows.Devices.Geolocation.PositionStatus.notAvailable:
+            // Location is not available on this version of Windows
+            return PositionError.POSITION_UNAVAILABLE;
+
+        case Windows.Devices.Geolocation.PositionStatus.disabled:
+            // The app doesn't have permission to access location,
+            // either because location has been turned off.
+            return PositionError.PERMISSION_DENIED;
+
+        default:
+            break;
+    }
+}
+function createResult(pos) {
+    var res = {
+        accuracy: pos.coordinate.accuracy,
+        heading: pos.coordinate.heading,
+        velocity: pos.coordinate.speed,
+        altitudeAccuracy: pos.coordinate.altitudeAccuracy,
+        timestamp: pos.coordinate.timestamp
+    }
+    
+    if (pos.coordinate.point) {
+        res.latitude = pos.coordinate.point.position.latitude;
+        res.longitude = pos.coordinate.point.position.longitude;
+        res.altitude = pos.coordinate.point.position.altitude;
+    } else { // compatibility with old windows8.0 api
+        res.latitude = pos.coordinate.latitude;
+        res.longitude = pos.coordinate.longitude;
+        res.altitude = pos.coordinate.altitude;
+    }
+    
+    return res;
+}
+
+module.exports = {
+    getLocation: function (success, fail, args, env) {
+        ensureLocator();
+        if (loc != null)
+        {
+            var highAccuracy = args[0],
+                maxAge = args[1];
+
+            loc.desiredAccuracy = highAccuracy ?
+                Windows.Devices.Geolocation.PositionAccuracy.high :
+                Windows.Devices.Geolocation.PositionAccuracy.default;
+
+            loc.reportInterval = maxAge ? maxAge : 0;
+
+            loc.getGeopositionAsync().then(
+                function (pos) {
+                    success(createResult(pos));
+                },
+                function (err) {
+                    fail({
+                        code: createErrorCode(),
+                        message: err.message
+                    });
+                }
+            );
+        }
+        else
+        {
+            fail({
+                code: PositionError.POSITION_UNAVAILABLE,
+                message: "You do not have the required location services present on your
system."
+            });
+        }
+    },
+
+    addWatch: function (success, fail, args, env) {
+        ensureLocator();
+        var clientId = args[0],
+            highAccuracy = args[1],
+
+            onPositionChanged = function (e) {
+                success(createResult(e.position));
+            },
+
+            onStatusChanged = function (e) {
+                switch (e.status) {
+                    case Windows.Devices.Geolocation.PositionStatus.noData:
+                    case Windows.Devices.Geolocation.PositionStatus.notAvailable:
+                        fail({
+                            code: PositionError.POSITION_UNAVAILABLE,
+                            message: "Data from location services is currently unavailable
or you do not have the required location services present on your system."
+                        });
+                        break;
+
+                    case Windows.Devices.Geolocation.PositionStatus.disabled:
+                        fail({
+                            code: PositionError.PERMISSION_DENIED,
+                            message: "Your location is currently turned off."
+                        });
+                        break;
+
+                    case Windows.Devices.Geolocation.PositionStatus.initializing:
+                    case Windows.Devices.Geolocation.PositionStatus.ready:
+                    default:
+                        break;
+                }
+            };
+
+        loc.desiredAccuracy = highAccuracy ?
+                Windows.Devices.Geolocation.PositionAccuracy.high :
+                Windows.Devices.Geolocation.PositionAccuracy.default;
+
+        loc.addEventListener("positionchanged", onPositionChanged);
+        loc.addEventListener("statuschanged", onStatusChanged);
+
+        ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+    },
+
+    clearWatch: function (success, fail, args, env) {
+        var clientId = args[0],
+            callbacks = ids[clientId];
+
+        if (callbacks) {
+            loc.removeEventListener("positionchanged", callbacks.pos);
+            loc.removeEventListener("statuschanged", callbacks.status);
+
+            delete ids[clientId];
+        }
+
+        success && success();
+    }
+};
+
+require("cordova/exec/proxy").add("Geolocation", module.exports);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/4137f9dd/src/windows8/GeolocationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/GeolocationProxy.js b/src/windows8/GeolocationProxy.js
deleted file mode 100644
index 6fca696..0000000
--- a/src/windows8/GeolocationProxy.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2013 Research In Motion Limited.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-var PositionError = require('./PositionError'),
-    ids = {},
-    loc;
-
-function ensureLocator() {
-    if (loc == null)
-        loc = new Windows.Devices.Geolocation.Geolocator();
-
-    return loc;
-}
-
-function createErrorCode() {
-    switch (loc.locationStatus) {
-        case Windows.Devices.Geolocation.PositionStatus.initializing:
-            // This status indicates that a location device is still initializing
-        case Windows.Devices.Geolocation.PositionStatus.noData:
-            // No location data is currently available 
-        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. 
-        case Windows.Devices.Geolocation.PositionStatus.notAvailable:
-            // Location is not available on this version of Windows
-            return PositionError.POSITION_UNAVAILABLE;
-
-        case Windows.Devices.Geolocation.PositionStatus.disabled:
-            // The app doesn't have permission to access location,
-            // either because location has been turned off.
-            return PositionError.PERMISSION_DENIED;
-
-        default:
-            break;
-    }
-}
-function createResult(pos) {
-    return {
-        latitude: pos.coordinate.latitude,
-        longitude: pos.coordinate.longitude,
-        altitude: pos.coordinate.altitude,
-        accuracy: pos.coordinate.accuracy,
-        heading: pos.coordinate.heading,
-        velocity: pos.coordinate.speed,
-        altitudeAccuracy: pos.coordinate.altitudeAccuracy,
-        timestamp: pos.coordinate.timestamp
-    };
-}
-
-module.exports = {
-    getLocation: function (success, fail, args, env) {
-        ensureLocator();
-        if (loc != null)
-        {
-            var highAccuracy = args[0],
-                maxAge = args[1];
-
-            loc.desiredAccuracy = highAccuracy ?
-                Windows.Devices.Geolocation.PositionAccuracy.high :
-                Windows.Devices.Geolocation.PositionAccuracy.default;
-
-            loc.reportInterval = maxAge ? maxAge : 0;
-
-            loc.getGeopositionAsync().then(
-                function (pos) {
-                    success(getResult(pos));
-                },
-                function (err) {
-                    fail({
-                        code: createErrorCode(),
-                        message: err.message
-                    });
-                }
-            );
-        }
-        else
-        {
-            fail({
-                code: PositionError.POSITION_UNAVAILABLE,
-                message: "You do not have the required location services present on your
system."
-            });
-        }
-    },
-
-    addWatch: function (success, fail, args, env) {
-        ensureLocator();
-        var clientId = args[0],
-            highAccuracy = args[1],
-
-            onPositionChanged = function (e) {
-                success(getResult(e.position));
-            },
-
-            onStatusChanged = function (e) {
-                switch (e.status) {
-                    case Windows.Devices.Geolocation.PositionStatus.noData:
-                    case Windows.Devices.Geolocation.PositionStatus.notAvailable:
-                        fail({
-                            code: PositionError.POSITION_UNAVAILABLE,
-                            message: "Data from location services is currently unavailable
or you do not have the required location services present on your system."
-                        });
-                        break;
-
-                    case Windows.Devices.Geolocation.PositionStatus.disabled:
-                        fail({
-                            code: PositionError.PERMISSION_DENIED,
-                            message: "Your location is currently turned off."
-                        });
-                        break;
-
-                    case Windows.Devices.Geolocation.PositionStatus.initializing:
-                    case Windows.Devices.Geolocation.PositionStatus.ready:
-                    default:
-                        break;
-                }
-            };
-
-        loc.desiredAccuracy = highAccuracy ?
-                Windows.Devices.Geolocation.PositionAccuracy.high :
-                Windows.Devices.Geolocation.PositionAccuracy.default;
-
-        loc.addEventListener("positionchanged", onPositionChanged);
-        loc.addEventListener("statuschanged", onStatusChanged);
-
-        ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
-    },
-
-    clearWatch: function (success, fail, args, env) {
-        var clientId = args[0],
-            callbacks = ids[clientId];
-
-        if (callbacks) {
-            loc.removeEventListener("positionchanged", callbacks.pos);
-            loc.removeEventListener("statuschanged", callbacks.status);
-
-            delete ids[clientId];
-        }
-
-        success && success();
-    }
-};
-
-require("cordova/exec/proxy").add("Geolocation", module.exports);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/4137f9dd/src/windows81/GeolocationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows81/GeolocationProxy.js b/src/windows81/GeolocationProxy.js
deleted file mode 100644
index c954a4b..0000000
--- a/src/windows81/GeolocationProxy.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2013 Research In Motion Limited.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-var PositionError = require('./PositionError'),
-    ids = {},
-    loc;
-
-function ensureLocator() {
-    if (loc == null)
-        loc = new Windows.Devices.Geolocation.Geolocator();
-
-    return loc;
-}
-
-function createErrorCode() {
-    switch (loc.locationStatus) {
-        case Windows.Devices.Geolocation.PositionStatus.initializing:
-            // This status indicates that a location device is still initializing
-        case Windows.Devices.Geolocation.PositionStatus.noData:
-            // No location data is currently available 
-        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. 
-        case Windows.Devices.Geolocation.PositionStatus.notAvailable:
-            // Location is not available on this version of Windows
-            return PositionError.POSITION_UNAVAILABLE;
-
-        case Windows.Devices.Geolocation.PositionStatus.disabled:
-            // The app doesn't have permission to access location,
-            // either because location has been turned off.
-            return PositionError.PERMISSION_DENIED;
-
-        default:
-            break;
-    }
-}
-function createResult(pos) {
-    return {
-        latitude: pos.coordinate.point.position.latitude,
-        longitude: pos.coordinate.point.position.longitude,
-        altitude: pos.coordinate.point.position.altitude,
-        accuracy: pos.coordinate.accuracy,
-        heading: pos.coordinate.heading,
-        velocity: pos.coordinate.speed,
-        altitudeAccuracy: pos.coordinate.altitudeAccuracy,
-        timestamp: pos.coordinate.timestamp
-    };
-}
-
-module.exports = {
-    getLocation: function (success, fail, args, env) {
-        ensureLocator();
-        if (loc != null)
-        {
-            var highAccuracy = args[0],
-                maxAge = args[1];
-
-            loc.desiredAccuracy = highAccuracy ?
-                Windows.Devices.Geolocation.PositionAccuracy.high :
-                Windows.Devices.Geolocation.PositionAccuracy.default;
-
-            loc.reportInterval = maxAge ? maxAge : 0;
-
-            loc.getGeopositionAsync().then(
-                function (pos) {
-                    success(createResult(pos));
-                },
-                function (err) {
-                    fail({
-                        code: createErrorCode(),
-                        message: err.message
-                    });
-                }
-            );
-        }
-        else
-        {
-            fail({
-                code: PositionError.POSITION_UNAVAILABLE,
-                message: "You do not have the required location services present on your
system."
-            });
-        }
-    },
-
-    addWatch: function (success, fail, args, env) {
-        ensureLocator();
-        var clientId = args[0],
-            highAccuracy = args[1],
-
-            onPositionChanged = function (e) {
-                success(createResult(e.position));
-            },
-
-            onStatusChanged = function (e) {
-                switch (e.status) {
-                    case Windows.Devices.Geolocation.PositionStatus.noData:
-                    case Windows.Devices.Geolocation.PositionStatus.notAvailable:
-                        fail({
-                            code: PositionError.POSITION_UNAVAILABLE,
-                            message: "Data from location services is currently unavailable
or you do not have the required location services present on your system."
-                        });
-                        break;
-
-                    case Windows.Devices.Geolocation.PositionStatus.disabled:
-                        fail({
-                            code: PositionError.PERMISSION_DENIED,
-                            message: "Your location is currently turned off."
-                        });
-                        break;
-
-                    case Windows.Devices.Geolocation.PositionStatus.initializing:
-                    case Windows.Devices.Geolocation.PositionStatus.ready:
-                    default:
-                        break;
-                }
-            };
-
-        loc.desiredAccuracy = highAccuracy ?
-                Windows.Devices.Geolocation.PositionAccuracy.high :
-                Windows.Devices.Geolocation.PositionAccuracy.default;
-
-        loc.addEventListener("positionchanged", onPositionChanged);
-        loc.addEventListener("statuschanged", onStatusChanged);
-
-        ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
-    },
-
-    clearWatch: function (success, fail, args, env) {
-        var clientId = args[0],
-            callbacks = ids[clientId];
-
-        if (callbacks) {
-            loc.removeEventListener("positionchanged", callbacks.pos);
-            loc.removeEventListener("statuschanged", callbacks.status);
-
-            delete ids[clientId];
-        }
-
-        success && success();
-    }
-};
-
-require("cordova/windows8/commandProxy").add("Geolocation", module.exports);
\ No newline at end of file


Mime
View raw message