Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E036718073 for ; Mon, 4 Jan 2016 08:15:08 +0000 (UTC) Received: (qmail 12688 invoked by uid 500); 4 Jan 2016 08:15:08 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 12658 invoked by uid 500); 4 Jan 2016 08:15:08 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 12649 invoked by uid 99); 4 Jan 2016 08:15:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jan 2016 08:15:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9424EDFF30; Mon, 4 Jan 2016 08:15:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sgrebnov@apache.org To: commits@cordova.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: cordova-plugin-geolocation git commit: CB-10278 geolocation watchPosition doesn't return watchID string Date: Mon, 4 Jan 2016 08:15:08 +0000 (UTC) Repository: cordova-plugin-geolocation Updated Branches: refs/heads/master 4f9dcf02f -> 49825f17e CB-10278 geolocation watchPosition doesn't return watchID string gtihub close #63 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/49825f17 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/49825f17 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/49825f17 Branch: refs/heads/master Commit: 49825f17e56dc6df2e8bf50b3fa03a93960ff5e1 Parents: 4f9dcf0 Author: sgrebnov Authored: Mon Jan 4 11:15:11 2016 +0300 Committer: sgrebnov Committed: Mon Jan 4 11:15:11 2016 +0300 ---------------------------------------------------------------------- tests/tests.js | 1 + www/android/geolocation.js | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/49825f17/tests/tests.js ---------------------------------------------------------------------- diff --git a/tests/tests.js b/tests/tests.js index b32607b..5d87375 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -209,6 +209,7 @@ exports.defineAutoTests = function () { { maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position }); + expect(successWatch).toBeDefined(); }); }); http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/49825f17/www/android/geolocation.js ---------------------------------------------------------------------- diff --git a/www/android/geolocation.js b/www/android/geolocation.js index df08071..e1d678b 100644 --- a/www/android/geolocation.js +++ b/www/android/geolocation.js @@ -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 = {}; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org