Skip to content
Permalink
Browse files
CB-10278 geolocation watchPosition doesn't return watchID string
gtihub close #63
  • Loading branch information
sgrebnov committed Jan 4, 2016
1 parent 4f9dcf0 commit 49825f17e56dc6df2e8bf50b3fa03a93960ff5e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
@@ -209,6 +209,7 @@ exports.defineAutoTests = function () {
{
maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position
});
expect(successWatch).toBeDefined();
});

});
@@ -21,11 +21,10 @@


var exec = cordova.require('cordova/exec');
var utils = require('cordova/utils');

module.exports = {

/*TODO: Fix scope issues with this cordova.require. I have no idea exec works, but geo doesn't work */

getCurrentPosition: function(success, error, args) {
var win = function() {
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
@@ -35,19 +34,27 @@ module.exports = {
},

watchPosition: function(success, error, args) {
var pluginWatchId = utils.createUUID();

var win = function() {
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
geo.watchPosition(success, error, args);
pluginToNativeWatchMap[pluginWatchId] = geo.watchPosition(success, error, args);
};
exec(win, error, "Geolocation", "getPermission", []);

return pluginWatchId;
},

clearWatch: function(success, error, args) {
clearWatch: function(pluginWatchId) {
var win = function() {
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
geo.clearWatch(args[0]);
var nativeWatchId = pluginToNativeWatchMap[pluginWatchId];
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
geo.clearWatch(nativeWatchId);
}
exec(win, error, "Geolocation", "getPermission", []);
exec(win, null, "Geolocation", "getPermission", []);
}
};

// Native watchPosition method is called async after permissions prompt.
// So we use additional map and own ids to return watch id synchronously.
var pluginToNativeWatchMap = {};

0 comments on commit 49825f1

Please sign in to comment.