You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ro...@apache.org on 2015/08/20 01:11:39 UTC
cordova-plugin-geolocation git commit: CB-9355 Fix Geolocation plugin
start watch fail related to unset MovementThreshold on Windows 10
Repository: cordova-plugin-geolocation
Updated Branches:
refs/heads/master 239751944 -> f88dfd3a7
CB-9355 Fix Geolocation plugin start watch fail related to unset MovementThreshold on Windows 10
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/f88dfd3a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/f88dfd3a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/f88dfd3a
Branch: refs/heads/master
Commit: f88dfd3a7885ee0b596fccbd981d9f2ca4a19041
Parents: 2397519
Author: daserge <da...@yandex.ru>
Authored: Mon Jul 13 16:30:54 2015 +0300
Committer: daserge <da...@yandex.ru>
Committed: Wed Jul 15 00:52:42 2015 +0300
----------------------------------------------------------------------
src/windows/GeolocationProxy.js | 124 ++++++++++++++++++++---------------
1 file changed, 72 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/f88dfd3a/src/windows/GeolocationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js
index 9cab6a4..b1996c2 100644
--- a/src/windows/GeolocationProxy.js
+++ b/src/windows/GeolocationProxy.js
@@ -19,10 +19,30 @@ var PositionError = require('./PositionError'),
loc;
function ensureLocator() {
- if (loc == null)
+ var deferral;
+
+ if (loc == null) {
loc = new Windows.Devices.Geolocation.Geolocator();
- 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.'
+ });
+ });
+ } else {
+ deferral = WinJS.Promise.wrap(loc);
+ }
+ } else {
+ deferral = WinJS.Promise.wrap(loc);
+ }
+
+ return deferral;
}
function createErrorCode() {
@@ -72,46 +92,45 @@ function createResult(pos) {
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."
- });
- }
+ ensureLocator().done(function () {
+ 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."
+ });
+ }
+ }, fail);
},
addWatch: function (success, fail, args, env) {
- ensureLocator();
- var clientId = args[0],
+ ensureLocator().done(function () {
+ var clientId = args[0],
highAccuracy = args[1],
onPositionChanged = function (e) {
- success(createResult(e.position), {keepCallback: true});
+ success(createResult(e.position), { keepCallback: true });
},
onStatusChanged = function (e) {
@@ -138,22 +157,23 @@ module.exports = {
}
};
- loc.desiredAccuracy = highAccuracy ?
- Windows.Devices.Geolocation.PositionAccuracy.high :
- Windows.Devices.Geolocation.PositionAccuracy.default;
-
- if (cordova.platformId == 'windows' && WinJS.Utilities.isPhone) {
- // on Windows Phone 8.1 'positionchanged' event fails with error below if movementThreshold is not set
- // JavaScript runtime error: Operation aborted
- // You must set the MovementThreshold property or the ReportInterval property before adding event handlers.
- // WinRT information: You must set the MovementThreshold property or the ReportInterval property before adding event handlers
- loc.movementThreshold = loc.movementThreshold || 1; // 1 meter
- }
-
- loc.addEventListener("positionchanged", onPositionChanged);
- loc.addEventListener("statuschanged", onStatusChanged);
-
- ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+ loc.desiredAccuracy = highAccuracy ?
+ Windows.Devices.Geolocation.PositionAccuracy.high :
+ Windows.Devices.Geolocation.PositionAccuracy.default;
+
+ if (cordova.platformId == 'windows') {
+ // 'positionchanged' event fails with error below if movementThreshold is not set
+ // JavaScript runtime error: Operation aborted
+ // You must set the MovementThreshold property or the ReportInterval property before adding event handlers.
+ // WinRT information: You must set the MovementThreshold property or the ReportInterval property before adding event handlers
+ loc.movementThreshold = Number.EPSILON;
+ }
+
+ loc.addEventListener("positionchanged", onPositionChanged);
+ loc.addEventListener("statuschanged", onStatusChanged);
+
+ ids[clientId] = { pos: onPositionChanged, status: onStatusChanged };
+ }, fail);
},
clearWatch: function (success, fail, args, env) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org