You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by db...@apache.org on 2016/02/15 22:42:33 UTC
cordova-plugin-geolocation git commit: CB-10574: MobileSpec can't get
results for WP8.1 Builds
Repository: cordova-plugin-geolocation
Updated Branches:
refs/heads/master 4ab4d3a57 -> a6da270a0
CB-10574: MobileSpec can't get results for WP8.1 Builds
MobileSpec can't get results for WP8.1 Builds
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/a6da270a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/a6da270a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/a6da270a
Branch: refs/heads/master
Commit: a6da270a0bb8d6c83911d8d559c1bb37abe7bbcc
Parents: 4ab4d3a
Author: Sarangan Rajamanickam <sa...@microsoft.com>
Authored: Thu Feb 11 16:19:04 2016 -0800
Committer: Sarangan Rajamanickam <sa...@microsoft.com>
Committed: Fri Feb 12 20:22:28 2016 -0800
----------------------------------------------------------------------
src/windows/GeolocationProxy.js | 75 ++++++++++++++++++------------------
1 file changed, 37 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/a6da270a/src/windows/GeolocationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js
index f6188bc..9670e4f 100644
--- a/src/windows/GeolocationProxy.js
+++ b/src/windows/GeolocationProxy.js
@@ -14,47 +14,43 @@
* limitations under the License.
*/
-var PositionError = require('./PositionError'),
- ids = {},
- loc;
+var PositionError = require('./PositionError');
+var callbacks = {};
+var locs = {};
-function ensureLocator() {
+function ensureAndCreateLocator() {
var deferral;
- if (!loc) {
- loc = new Windows.Devices.Geolocation.Geolocator();
+ loc = new Windows.Devices.Geolocation.Geolocator();
- if (typeof Windows.Devices.Geolocation.Geolocator.requestAccessAsync === 'function') {
- deferral = Windows.Devices.Geolocation.Geolocator.requestAccessAsync().then(function (result) {
- if (result === Windows.Devices.Geolocation.GeolocationAccessStatus.allowed) {
- return loc;
- }
+ if (typeof Windows.Devices.Geolocation.Geolocator.requestAccessAsync === 'function') {
+ deferral = Windows.Devices.Geolocation.Geolocator.requestAccessAsync().then(function (result) {
+ if (result === Windows.Devices.Geolocation.GeolocationAccessStatus.allowed) {
+ return loc;
+ }
- return WinJS.Promise.wrapError({
- code: PositionError.PERMISSION_DENIED,
- message: 'Geolocation access has not been allowed by user.'
- });
+ return WinJS.Promise.wrapError({
+ code: PositionError.PERMISSION_DENIED,
+ message: 'Geolocation access has not been allowed by user.'
});
- } else {
- deferral = WinJS.Promise.wrap(loc);
- }
+ });
} else {
deferral = WinJS.Promise.wrap(loc);
- }
+ }
return deferral;
}
-function createErrorCode() {
+function createErrorCode(loc) {
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
+ // 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.
+ // 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;
@@ -76,7 +72,7 @@ function createResult(pos) {
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;
@@ -86,13 +82,13 @@ function createResult(pos) {
res.longitude = pos.coordinate.longitude;
res.altitude = pos.coordinate.altitude;
}
-
+
return res;
}
module.exports = {
getLocation: function (success, fail, args, env) {
- ensureLocator().done(function () {
+ ensureAndCreateLocator().done(function (loc) {
if (loc) {
var highAccuracy = args[0],
maxAge = args[1];
@@ -109,7 +105,7 @@ module.exports = {
},
function (err) {
fail({
- code: createErrorCode(),
+ code: createErrorCode(loc),
message: err.message
});
}
@@ -125,9 +121,9 @@ module.exports = {
},
addWatch: function (success, fail, args, env) {
- ensureLocator().done(function () {
- var clientId = args[0],
- highAccuracy = args[1],
+ ensureAndCreateLocator().done(function (loc) {
+ var clientId = args[0];
+ var highAccuracy = args[1];
onPositionChanged = function (e) {
success(createResult(e.position), { keepCallback: true });
@@ -172,19 +168,22 @@ module.exports = {
loc.addEventListener("positionchanged", onPositionChanged);
loc.addEventListener("statuschanged", onStatusChanged);
- ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
- }, fail);
+ callbacks[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+ locs[clientId] = loc;
+ }, fail);
},
clearWatch: function (success, fail, args, env) {
- var clientId = args[0],
- callbacks = ids[clientId];
+ var clientId = args[0];
+ var callback = callbacks[clientId];
+ var loc = locs[clientId]
- if (callbacks) {
- loc.removeEventListener("positionchanged", callbacks.pos);
- loc.removeEventListener("statuschanged", callbacks.status);
+ if (callback && loc) {
+ loc.removeEventListener("positionchanged", callback.pos);
+ loc.removeEventListener("statuschanged", callback.status);
- delete ids[clientId];
+ delete callbacks[clientId];
+ delete locs[clientId];
}
success();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org