diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 00000000..4cd6d535 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,28 @@ +# appveyor file +# http://www.appveyor.com/docs/appveyor-yml + +max_jobs: 1 + +shallow_clone: true + +init: + - git config --global core.autocrlf true + +image: + - Visual Studio 2017 + +environment: + nodejs_version: "4" + matrix: + - PLATFORM: windows-10-store + +install: + - npm cache clean -f + - node --version + - npm install -g cordova-paramedic@https://github.com/apache/cordova-paramedic.git + - npm install -g cordova + +build: off + +test_script: + - cordova-paramedic --config pr\%PLATFORM% --plugin . --justBuild diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 00000000..0cccb8c7 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,10 @@ +root: true +extends: semistandard +rules: + indent: + - error + - 4 + camelcase: off + padded-blocks: off + operator-linebreak: off + no-throw-literal: off \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index df324821..00000000 --- a/.jshintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "browser": true - , "devel": true - , "bitwise": true - , "undef": true - , "trailing": true - , "quotmark": false - , "indent": 4 - , "unused": "vars" - , "latedef": "nofunc" - , "globals": { - "module": false, - "exports": false, - "require": false, - "cordova": true - } -} diff --git a/.travis.yml b/.travis.yml index b9af4c58..db6d35bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,66 @@ -language: node_js sudo: false -node_js: - - "4.2" +addons: + jwt: + secure: yGb6UDaYlYgPpe6T3mqSvUbWrJAFeAJNQnVOFr9tfWEt9SdTmwrU68cEVMKmpc+nqCkvfrAn49XPzcERkgMDUQXPQzWHo87TfYpjqu3/+jfqyJy6RuE5ddbWQW05LtgRhjiPfmXmpAe41dbI7khl8Kx60zz9cxyHqBcR/k9bfFs= +env: + global: + - SAUCE_USERNAME=snay + - TRAVIS_NODE_VERSION="4.2" +matrix: + include: + - env: PLATFORM=ios-9.3 + os: osx + osx_image: xcode7.3 + language: node_js + node_js: '4.2' + - env: PLATFORM=ios-10.0 + os: osx + osx_image: xcode7.3 + language: node_js + node_js: '4.2' + - env: PLATFORM=android-4.4 + os: linux + language: android + jdk: oraclejdk8 + android: + components: + - tools + - env: PLATFORM=android-5.1 + os: linux + language: android + jdk: oraclejdk8 + android: + components: + - tools + - env: PLATFORM=android-6.0 + os: linux + language: android + jdk: oraclejdk8 + android: + components: + - tools + - env: PLATFORM=android-7.0 + os: linux + language: android + jdk: oraclejdk8 + android: + components: + - tools +before_install: +- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm + && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm + install $TRAVIS_NODE_VERSION +- node --version +- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi +- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi +- if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25,android-26; + fi +- git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic + && npm install && popd +- npm install -g cordova +install: +- npm install +script: +- npm test +- node /tmp/paramedic/main.js --config pr/$PLATFORM --plugin $(pwd) --shouldUseSauce + --buildName travis-plugin-geolocation-$TRAVIS_JOB_NUMBER diff --git a/README.md b/README.md index fae8b9ba..db86f785 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ description: Access GPS data. # under the License. --> -|Android 4.4|Android 5.1|iOS|Windows 10 Store|Travis CI| -|:-:|:-:|:-:|:-:|:-:| -|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-geolocation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-geolocation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-geolocation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-geolocation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-geolocation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-geolocation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-geolocation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-geolocation/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-geolocation.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-geolocation)| +|AppVeyor|Travis CI| +|:-:|:-:| +|[![Build status](https://ci.appveyor.com/api/projects/status/github/apache/cordova-plugin-geolocation?branch=master)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-plugin-geolocation)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-geolocation.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-geolocation)| # cordova-plugin-geolocation @@ -90,13 +90,8 @@ It is also possible to install via repo url directly ( unstable ) ## Supported Platforms -- Amazon Fire OS - Android -- BlackBerry 10 -- Firefox OS - iOS -- Tizen -- Windows Phone 7 and 8 - Windows ## Methods @@ -163,14 +158,19 @@ error, the `geolocationError` callback is passed a ### iOS Quirks - Since iOS 10 it's mandatory to add a `NSLocationWhenInUseUsageDescription` entry in the info.plist. - - `NSLocationWhenInUseUsageDescription` describes the reason that the app accesses the user's location. When the system prompts the user to allow access, this string is displayed as part of the dialog box. To add this entry you can pass the variable `GEOLOCATION_USAGE_DESCRIPTION` on plugin install. - - Example: - `cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="your usage message"` - - If you don't pass the variable, the plugin will add an empty string as value. + Since iOS 10 it's mandatory to provide an usage description in the `info.plist` if trying to access privacy-sensitive data. When the system prompts the user to allow access, this usage description string will displayed as part of the permission dialog box, but if you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description. + + This plugins requires the following usage description: + + * `NSLocationWhenInUseUsageDescription` describes the reason that the app accesses the user's location. + + To add this entry into the `info.plist`, you can use the `edit-config` tag in the `config.xml` like this: + +``` + + need location access to find things nearby + +``` ### Android Quirks @@ -307,10 +307,6 @@ It contains a set of properties that describe the geographic coordinates of a po * __speed__: Current ground speed of the device, specified in meters per second. _(Number)_ -### Amazon Fire OS Quirks - -__altitudeAccuracy__: Not supported by Android devices, returning `null`. - ### Android Quirks __altitudeAccuracy__: Not supported by Android devices, returning `null`. diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a5174289..12b5a75b 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,178 +1,3 @@ - -# Release Notes +### 4.0.1 (Dec 27, 2017) +* [CB-13705](https://issues.apache.org/jira/browse/CB-13705) Fix to allow 4.0.0 version install -### 2.4.1 (Dec 07, 2016) -* [CB-12224](https://issues.apache.org/jira/browse/CB-12224) Updated version and RELEASENOTES.md for release 2.4.1 -* corrected KCLAuthorizationStatus error, changed to always removed user of [manager locationServicesEnabled]. Must return [CLLocationManager locationServicesEnabled] or 'none' -* [CB-11962](https://issues.apache.org/jira/browse/CB-11962) (ios) Added variable for setting NSLocationWhenInUseUsageDescription -* [CB-11917](https://issues.apache.org/jira/browse/CB-11917) - Remove pull request template checklist item: "iCLA has been submitted…" -* [CB-11904](https://issues.apache.org/jira/browse/CB-11904) Incremented plugin version. - -### 2.4.0 (Sep 26, 2016) -* **Ubuntu** Fix altitude & accuracies retrieval -* [CB-11875](https://issues.apache.org/jira/browse/CB-11875) added `android.hardware.location.gps` `uses-feature`. - -### 2.3.0 (Sep 08, 2016) -* [CB-11795](https://issues.apache.org/jira/browse/CB-11795) Add 'protective' entry to cordovaDependencies -* Plugin uses `Android Log class` and not `Cordova LOG class` -* Add badges for paramedic builds on Jenkins -* Add pull request template. -* Adding links to reference content and sample content to the top of the readme file -* Update **iOS** geolocation plugin to avoid `THREAD WARNING: ['Geolocation']`, operation occurs in new Thread -* [CB-10996](https://issues.apache.org/jira/browse/CB-10996) Adding front matter to README.md - -### 2.2.0 (Apr 15, 2016) -* Replace `PermissionHelper.java` with `cordova-plugin-compat` -* [CB-10691](https://issues.apache.org/jira/browse/CB-10691) Check the context to avoid null errors -* [CB-10636](https://issues.apache.org/jira/browse/CB-10636) Add `JSHint` for plugins -* Using a fallback epsilon in case `Number.EPSILON` is not defined. -* [CB-10574](https://issues.apache.org/jira/browse/CB-10574) MobileSpec can't get results for **WP8.1** Builds - -### 2.1.0 (Jan 15, 2016) -* [CB-10319](https://issues.apache.org/jira/browse/CB-10319) **Android** Adding reflective helper methods for permission requests -* [CB-8523](https://issues.apache.org/jira/browse/CB-8523) Fixed accuracy when `enableHighAccuracy: false` on **iOS**. -* [CB-10286](https://issues.apache.org/jira/browse/CB-10286) Don't skip automatic tests on **Android** devices -* [CB-10277](https://issues.apache.org/jira/browse/CB-10277) Error callback should be called w/ `PositionError` when location access is denied -* [CB-10285](https://issues.apache.org/jira/browse/CB-10285) Added tests for `PositionError` constants -* [CB-10278](https://issues.apache.org/jira/browse/CB-10278) geolocation `watchPosition` doesn't return `watchID` string -* [CB-8443](https://issues.apache.org/jira/browse/CB-8443) **Android** nothing happens if `GPS` is turned off -* [CB-10204](https://issues.apache.org/jira/browse/CB-10204) Fix `getCurrentPosition` options on **Android** -* [CB-7146](https://issues.apache.org/jira/browse/CB-7146) Remove built-in `WebView navigator.geolocation` manual tests -* [CB-2845](https://issues.apache.org/jira/browse/CB-2845) `PositionError` constants not attached to prototype as specified in W3C document - -### 2.0.0 (Nov 18, 2015) -* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest -* [CB-9907](https://issues.apache.org/jira/browse/CB-9907) Handle **iOS** tests that fail when ios simulator does not have a location -* [CB-8826](https://issues.apache.org/jira/browse/CB-8826) Check for `NSLocationWhenInUseUsageDescription` first -* [CB-9105](https://issues.apache.org/jira/browse/CB-9105): Fixing `JS` errors in the shim -* Added support for new permissions model for **Android 6.0** aka **Marshmallow** -* Expect `lastPosition` to have a `timestamp` that is already in `msecs` -* [CB-4596](https://issues.apache.org/jira/browse/CB-4596) Date objects are supposed to be `DOMTimeStamp` -* Fixing contribute link. -* [CB-9355](https://issues.apache.org/jira/browse/CB-9355) Fix Geolocation plugin start watch fail related to unset `MovementThreshold` on **Windows 10** - -### 1.0.1 (Jun 17, 2015) -* [CB-9128](https://issues.apache.org/jira/browse/CB-9128) cordova-plugin-geolocation documentation translation: cordova-plugin-geolocation -* fix npm md issue -* [CB-8845](https://issues.apache.org/jira/browse/CB-8845) Updated comment why Android tests are currently pended -* [CB-8845](https://issues.apache.org/jira/browse/CB-8845) Pended tests for Android -* Add more install text for legacy versions of cordova tools. This closes #36 - -### 1.0.0 (Apr 15, 2015) -* [CB-8746](https://issues.apache.org/jira/browse/CB-8746) gave plugin major version bump -* [CB-8683](https://issues.apache.org/jira/browse/CB-8683) changed plugin-id to pacakge-name -* [CB-8653](https://issues.apache.org/jira/browse/CB-8653) properly updated translated docs to use new id -* [CB-8653](https://issues.apache.org/jira/browse/CB-8653) updated translated docs to use new id -* Use TRAVIS_BUILD_DIR, install paramedic by npm -* [CB-8681](https://issues.apache.org/jira/browse/CB-8681) Fixed occasional test failures -* docs: added Windows to supported platforms -* [CB-8653](https://issues.apache.org/jira/browse/CB-8653) Updated Readme -* [CB-8659](https://issues.apache.org/jira/browse/CB-8659): ios: 4.0.x Compatibility: Remove use of initWebView method -* [CB-8659](https://issues.apache.org/jira/browse/CB-8659): ios: 4.0.x Compatibility: Remove use of deprecated headers -* Wrong parameter in Firefox OS plugin -* [CB-8568](https://issues.apache.org/jira/browse/CB-8568) Integrate TravisCI -* [CB-8438](https://issues.apache.org/jira/browse/CB-8438) cordova-plugin-geolocation documentation translation: cordova-plugin-geolocation -* [CB-8538](https://issues.apache.org/jira/browse/CB-8538) Added package.json file -* [CB-8443](https://issues.apache.org/jira/browse/CB-8443) Geolocation tests fail on Windows due to done is called multiple times - -### 0.3.12 (Feb 04, 2015) -* [CB-8351](https://issues.apache.org/jira/browse/CB-8351) ios: Use argumentForIndex rather than NSArray extension - -### 0.3.11 (Dec 02, 2014) -* Do not stop updating location when the error is `kCLErrorLocationUnknown` -* [CB-8094](https://issues.apache.org/jira/browse/CB-8094) Pended auto tests for **Windows** Store since they require user interaction -* [CB-8085](https://issues.apache.org/jira/browse/CB-8085) Fix geolocation plugin on **Windows** -* [CB-7977](https://issues.apache.org/jira/browse/CB-7977) Mention `deviceready` in plugin docs -* [CB-7700](https://issues.apache.org/jira/browse/CB-7700) cordova-plugin-geolocation documentation translation: cordova-plugin-geolocation - -### 0.3.10 (Sep 17, 2014) -* [CB-7556](https://issues.apache.org/jira/browse/CB-7556) iOS: Clearing all Watches does not stop Location Services -* [CB-7158](https://issues.apache.org/jira/browse/CB-7158) Fix geolocation for ios 8 -* Revert [CB-6911](https://issues.apache.org/jira/browse/CB-6911) partially (keeping Info.plist key installation for iOS 8) -* [CB-6911](https://issues.apache.org/jira/browse/CB-6911) Geolocation fails in iOS 8 -* [CB-5114](https://issues.apache.org/jira/browse/CB-5114) Windows 8.1 - Use a new proxy as old geolocation methods is deprecated -* [CB-5114](https://issues.apache.org/jira/browse/CB-5114) Append Windows 8.1 into plugin.xml + Optimize Windows 8 Geolocation proxy -* Renamed test dir, added nested plugin.xml -* added documentation for manual tests -* [CB-7146](https://issues.apache.org/jira/browse/CB-7146) Added manual tests -* Removed js-module for tests from plugin.xml -* Changing cdvtest format to use module exports -* register tests using new style -* Convert tests to new style -* Removed amazon-fireos code for geolocation. -* [CB-7571](https://issues.apache.org/jira/browse/CB-7571) Bump version of nested plugin to match parent plugin - -### 0.3.9 (Aug 06, 2014) -* **FFOS** update GeolocationProxy.js -* [CB-7187](https://issues.apache.org/jira/browse/CB-7187) ios: Add explicit dependency on CoreLocation.framework -* [CB-7187](https://issues.apache.org/jira/browse/CB-7187) Delete unused #import of CDVShared.h -* [CB-6127](https://issues.apache.org/jira/browse/CB-6127) Updated translations for docs -* ios: Changed distanceFilter from none to 5 meters, prevents it from spamming the callback even though nothing changed. - -### 0.3.8 (Jun 05, 2014) -* [CB-6127](https://issues.apache.org/jira/browse/CB-6127) Spanish and French Translations added. Github close #14 -* [CB-6804](https://issues.apache.org/jira/browse/CB-6804) Add license -* [CB-5416](https://issues.apache.org/jira/browse/CB-5416) - Adding support for auto-managing permissions -* [CB-6491](https://issues.apache.org/jira/browse/CB-6491) add CONTRIBUTING.md -* pass by only coords -* proper implementation for firefoxos -* call FxOS's getCurrentProxy added - -### 0.3.7 (Apr 17, 2014) -* [CB-6422](https://issues.apache.org/jira/browse/CB-6422): [windows8] use cordova/exec/proxy -* [CB-6212](https://issues.apache.org/jira/browse/CB-6212): [iOS] fix warnings compiled under arm64 64-bit -* [CB-5977](https://issues.apache.org/jira/browse/CB-5977): [android] Removing the Android Geolocation Code. Mission Accomplished. -* [CB-6460](https://issues.apache.org/jira/browse/CB-6460): Update license headers -* Add NOTICE file - -### 0.3.6 (Feb 05, 2014) -* add ubuntu platform support -* [CB-5326](https://issues.apache.org/jira/browse/CB-5326) adding FFOS permission and updating supported platforms -* [CB-5729](https://issues.apache.org/jira/browse/CB-5729) [BlackBerry10] Update GeolocationProxy to return collapsed object - -### 0.3.5 (Jan 02, 2014) -* [CB-5658](https://issues.apache.org/jira/browse/CB-5658) Add doc/index.md for Geolocation plugin -* windows8: adds missing reference to PositionError (w/o it the app crashes) -* Removing incorrectly added closing comments for wp7 platform in plugin.xml - -### 0.3.4 (Dec 4, 2013) -* Append proxy to platform definition in plugin.xml -* Append windows 8 Geolocation proxy -* Code clean-up for android src. -* Updated amazon-fireos platform + reverting some of the fixes in android code. -* Added amazon-fireos platform + some of the fixes in android code. -* [CB-5334](https://issues.apache.org/jira/browse/CB-5334) [BlackBerry10] Use command proxy -* call FxOS's getCurrentProxy added -* pass by only coords -* proper implementation for firefoxos - -### 0.3.3 (Oct 28, 2013) -* [CB-5128](https://issues.apache.org/jira/browse/CB-5128): add repo + issue tag to plugin.xml for geolocation plugin -* [CB-4915](https://issues.apache.org/jira/browse/CB-4915) Incremented plugin version on dev branch. - -### 0.3.2 (Sept 25, 2013) -* [CB-4889](https://issues.apache.org/jira/browse/CB-4889) bumping&resetting version -* [BlackBerry10] removed uneeded permission tags in plugin.xml -* [CB-4889](https://issues.apache.org/jira/browse/CB-4889) renaming org.apache.cordova.core.geolocation to org.apache.cordova.geolocation - -### 0.3.0 (Sept 5, 2013) -* Added support for windows 8 (Adds required permission) diff --git a/package.json b/package.json index ea3600cd..0aae0135 100644 --- a/package.json +++ b/package.json @@ -1,55 +1,53 @@ { "name": "cordova-plugin-geolocation", - "version": "2.4.2-dev", + "version": "4.0.1", "description": "Cordova Geolocation Plugin", "cordova": { "id": "cordova-plugin-geolocation", "platforms": [ "android", - "amazon-fireos", "ios", - "blackberry10", - "ubuntu", - "wp7", - "wp8", - "windows8", - "windows", - "firefoxos" + "windows" ] }, "repository": { "type": "git", "url": "https://github.com/apache/cordova-plugin-geolocation" }, + "bugs": { + "url": "https://issues.apache.org/jira/browse/CB" + }, "keywords": [ "cordova", "geolocation", "ecosystem:cordova", "cordova-android", - "cordova-amazon-fireos", "cordova-ios", - "cordova-blackberry10", - "cordova-ubuntu", - "cordova-wp7", - "cordova-wp8", - "cordova-windows8", - "cordova-windows", - "cordova-firefoxos" + "cordova-windows" ], "scripts": { - "test": "npm run jshint", - "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" + "test": "npm run eslint", + "eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests" }, "author": "Apache Software Foundation", "license": "Apache-2.0", "engines": { "cordovaDependencies": { "3.0.0": { + "cordova-android": ">=6.3.0" + }, + "5.0.0": { "cordova": ">100" } } }, "devDependencies": { - "jshint": "^2.6.0" + "eslint": "^4.0.0", + "eslint-config-semistandard": "^11.0.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-node": "^5.0.0", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1" } } diff --git a/plugin.xml b/plugin.xml index 8c553922..d4fe505b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -22,7 +22,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-geolocation" - version="2.4.2-dev"> + version="4.0.1"> Geolocation Cordova Geolocation Plugin @@ -31,7 +31,9 @@ xmlns:android="http://schemas.android.com/apk/res/android" https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git https://issues.apache.org/jira/browse/CB/component/12320638 - + + + @@ -59,16 +61,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" - - - - - - - - - - @@ -98,119 +90,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" - - - - $GEOLOCATION_USAGE_DESCRIPTION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - read_geolocation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -239,31 +119,4 @@ xmlns:android="http://schemas.android.com/apk/res/android" - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/firefoxos/GeolocationProxy.js b/src/firefoxos/GeolocationProxy.js deleted file mode 100644 index e4b40529..00000000 --- a/src/firefoxos/GeolocationProxy.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * -*/ - -// latest geolocation spec can be found here: http://www.w3.org/TR/geolocation-API/ - -var idsMap = {}; - -module.exports = { - getLocation: function(success, error, args) { - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); - function successCallback(position) { - // Cordova is creating Position object using just coords - success(position.coords); - } - geo.getCurrentPosition(successCallback, error, { - enableHighAccuracy: args[0], - maximumAge: args[1] - }); - }, - - addWatch: function(success, error, args) { - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); - var id = args[0]; - function successCallback(position) { - success(position.coords); - } - var nativeId = geo.watchPosition(successCallback, error, { - enableHighAccuracy: args[1] - }); - - idsMap[id] = nativeId; - }, - - clearWatch: function(success, error, args) { - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); - var id = args[0]; - - if(id in idsMap) { - geo.clearWatch(idsMap[id]); - delete idsMap[id]; - } - - if(success) { - success(); - } - } -}; - -require("cordova/exec/proxy").add("Geolocation", module.exports); diff --git a/src/ubuntu/geolocation.cpp b/src/ubuntu/geolocation.cpp deleted file mode 100644 index 3d40ab4c..00000000 --- a/src/ubuntu/geolocation.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * Copyright 2013-2016 Canonical Ltd. - * - * 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. - * -*/ - -#include - -#include "geolocation.h" - -Geolocation::Geolocation(Cordova *cordova) - : CPlugin(cordova), - _geoPositionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)) { - if (_geoPositionInfoSource.data() != 0) { - QObject::connect(_geoPositionInfoSource.data(), - SIGNAL(positionUpdated(QGeoPositionInfo)), - this, - SLOT(positionUpdated(QGeoPositionInfo))); - - QObject::connect(_geoPositionInfoSource.data(), - SIGNAL(updateTimeout()), - this, - SLOT(updateTimeout())); - } -} - -void Geolocation::addWatch(int scId, int ecId, const QString &id, bool enableHighAccuracy) { - Q_UNUSED(enableHighAccuracy); - - assert(_id2sc.find(id) == _id2sc.end()); - - if (!_geoPositionInfoSource.data()) { - QVariantMap err; - err.insert("code", POSITION_UNAVAILABLE); - err.insert("message", "unavailable"); - - this->cb(ecId, err); - return; - } - - _id2sc[id] = scId; - _id2ec[id] = ecId; -} - -void Geolocation::clearWatch(int scId, int ecId, const QString &id) { - _id2sc.remove(id); - _id2ec.remove(id); -} - -void Geolocation::getLocation(int scId, int ecId, bool enableHighAccuracy, qint64 maximumAge) { - Q_UNUSED(maximumAge); - Q_UNUSED(enableHighAccuracy); - - if (!_geoPositionInfoSource.data()) { - QVariantMap err; - err.insert("code", POSITION_UNAVAILABLE); - err.insert("message", "unavailable"); - - this->cb(ecId, err); - return; - } - - _geoPositionInfoSource->requestUpdate(); - - QString id = QString("_INTERNAL_") + QUuid::createUuid().toString(); - - _id2sc[id] = scId; - _id2ec[id] = ecId; - _singleUpdate.insert(id); -} - -void Geolocation::positionUpdated(const QGeoPositionInfo &update) { - QGeoCoordinate coordinate = update.coordinate(); - - QVariantMap p; - - p.insert("latitude", coordinate.latitude()); - p.insert("longitude", coordinate.longitude()); - - if (coordinate.type() == QGeoCoordinate::Coordinate3D) - p.insert("altitude", coordinate.altitude()); - - if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) - p.insert("accuracy", update.attribute(QGeoPositionInfo::HorizontalAccuracy)); - - if (update.hasAttribute(QGeoPositionInfo::Direction)) - p.insert("heading", update.attribute(QGeoPositionInfo::Direction)); - - if (update.hasAttribute(QGeoPositionInfo::GroundSpeed)) - p.insert("velocity", update.attribute(QGeoPositionInfo::GroundSpeed)); - - if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) - p.insert("altitudeAccuracy", update.attribute(QGeoPositionInfo::VerticalAccuracy)); - - p.insert("timestamp", update.timestamp().toMSecsSinceEpoch()); - - for (const QString &id: _id2sc.keys()) { - int scId = _id2sc[id]; - this->cb(scId, p); - if (_singleUpdate.contains(id)) { - _singleUpdate.remove(id); - _id2sc.remove(id); - _id2ec.remove(id); - } - } -} - -void Geolocation::updateTimeout() { - QVariantMap err; - err.insert("code", TIMEOUT); - err.insert("message", "timeout"); - - for (int ecId: _id2ec) { - this->cb(ecId, err); - } - - _id2ec.clear(); - _id2sc.clear(); - _singleUpdate.clear(); -} diff --git a/src/ubuntu/geolocation.h b/src/ubuntu/geolocation.h deleted file mode 100644 index 7345bec9..00000000 --- a/src/ubuntu/geolocation.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Copyright 2013 Canonical Ltd. - * - * 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. - * -*/ - -#ifndef GEOLOCATION_H_SVO2013 -#define GEOLOCATION_H_SVO2013 - -#include -#include -#include -#include - -#include - -class Geolocation: public CPlugin { - Q_OBJECT -public: - explicit Geolocation(Cordova *cordova); - - virtual const QString fullName() override { - return Geolocation::fullID(); - } - - virtual const QString shortName() override { - return "Geolocation"; - } - - static const QString fullID() { - return "Geolocation"; - } - -public slots: - void getLocation(int scId, int ecId, bool enableHighAccuracy, qint64 maximumAge); - void addWatch(int scId, int ecId, const QString &id, bool enableHighAccuracy); - void clearWatch(int scId, int ecId, const QString &id); - -protected slots: - void positionUpdated(const QGeoPositionInfo &update); - void updateTimeout(); - -private: - QMap _id2sc; - QMap _id2ec; - QSet _singleUpdate; - QSharedPointer _geoPositionInfoSource; - - enum PositionError { - PERMISSION_DENIED = 1, - POSITION_UNAVAILABLE = 2, - TIMEOUT = 3 - }; -}; - -#endif diff --git a/src/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js index 03ed4950..f792b912 100644 --- a/src/windows/GeolocationProxy.js +++ b/src/windows/GeolocationProxy.js @@ -16,14 +16,14 @@ /* global Windows, WinJS */ -var PositionError = require('./PositionError'); -var callbacks = {}; -var locs = {}; +var PositionError = require('./PositionError'); +var callbacks = {}; +var locs = {}; // constants var FALLBACK_EPSILON = 0.001; -function ensureAndCreateLocator() { +function ensureAndCreateLocator () { var deferral; var loc = new Windows.Devices.Geolocation.Geolocator(); @@ -46,30 +46,32 @@ function ensureAndCreateLocator() { return deferral; } -function createErrorCode(loc) { +function createErrorCode (loc) { + /* eslint-disable no-fallthrough */ 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; + 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) { +/* eslint-enable no-fallthrough */ +function createResult (pos) { var res = { accuracy: pos.coordinate.accuracy, heading: pos.coordinate.heading, @@ -95,14 +97,14 @@ module.exports = { getLocation: function (success, fail, args, env) { ensureAndCreateLocator().done(function (loc) { if (loc) { - var highAccuracy = args[0], - maxAge = args[1]; + var highAccuracy = args[0]; + var maxAge = args[1]; loc.desiredAccuracy = highAccuracy ? Windows.Devices.Geolocation.PositionAccuracy.high : Windows.Devices.Geolocation.PositionAccuracy.default; - loc.reportInterval = maxAge ? maxAge : 0; + loc.reportInterval = maxAge || 0; loc.getGeopositionAsync().then( function (pos) { @@ -115,11 +117,10 @@ module.exports = { }); } ); - } - else { + } else { fail({ code: PositionError.POSITION_UNAVAILABLE, - message: "You do not have the required location services present on your system." + message: 'You do not have the required location services present on your system.' }); } }, fail); @@ -136,33 +137,33 @@ module.exports = { var 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.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; + default: + break; } }; loc.desiredAccuracy = highAccuracy ? - Windows.Devices.Geolocation.PositionAccuracy.high : - Windows.Devices.Geolocation.PositionAccuracy.default; + Windows.Devices.Geolocation.PositionAccuracy.high : + Windows.Devices.Geolocation.PositionAccuracy.default; - if (cordova.platformId == 'windows') { + if (cordova.platformId === 'windows') { // eslint-disable-line no-undef // '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. @@ -174,8 +175,8 @@ module.exports = { } } - loc.addEventListener("positionchanged", onPositionChanged); - loc.addEventListener("statuschanged", onStatusChanged); + loc.addEventListener('positionchanged', onPositionChanged); + loc.addEventListener('statuschanged', onStatusChanged); callbacks[clientId] = { pos: onPositionChanged, status: onStatusChanged }; locs[clientId] = loc; @@ -185,11 +186,11 @@ module.exports = { clearWatch: function (success, fail, args, env) { var clientId = args[0]; var callback = callbacks[clientId]; - var loc = locs[clientId]; + var loc = locs[clientId]; if (callback && loc) { - loc.removeEventListener("positionchanged", callback.pos); - loc.removeEventListener("statuschanged", callback.status); + loc.removeEventListener('positionchanged', callback.pos); + loc.removeEventListener('statuschanged', callback.status); delete callbacks[clientId]; delete locs[clientId]; @@ -199,4 +200,4 @@ module.exports = { } }; -require("cordova/exec/proxy").add("Geolocation", module.exports); +require('cordova/exec/proxy').add('Geolocation', module.exports); diff --git a/src/wp/GeoLocation.cs b/src/wp/GeoLocation.cs deleted file mode 100644 index 42af72de..00000000 --- a/src/wp/GeoLocation.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - 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. -*/ - -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using System.Threading; -using System.Device.Location; - -namespace WPCordovaClassLib.Cordova.Commands -{ - /// - /// This is a command stub, the browser provides the correct implementation. We use this to trigger the static analyzer that we require this permission - /// - public class Geolocation - { - /* Unreachable code, by design -jm */ - private void triggerGeoInclusion() - { - new GeoCoordinateWatcher(); - } - } -} diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 00000000..b1e0d866 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,14 @@ +{ + "name": "cordova-plugin-geolocation-tests", + "version": "2.4.3-dev", + "description": "", + "cordova": { + "id": "cordova-plugin-geolocation-tests", + "platforms": [] + }, + "keywords": [ + "ecosystem:cordova" + ], + "author": "", + "license": "Apache 2.0" +} diff --git a/tests/plugin.xml b/tests/plugin.xml index d06d5a78..5f969788 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -22,11 +22,14 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-geolocation-tests" - version="2.4.2-dev"> + version="4.0.1"> Cordova Geolocation Plugin Tests Apache 2.0 + + need location access to pass tests + diff --git a/tests/tests.js b/tests/tests.js index 50c5bfb2..cf3a5ab5 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,7 +19,7 @@ * */ -/* jshint jasmine: true */ +/* eslint-env jasmine */ /* global WinJS, device */ exports.defineAutoTests = function () { @@ -42,7 +42,7 @@ exports.defineAutoTests = function () { done(); }); }; - + var succeed = function (done, context) { // prevents done() to be called several times if (context) { @@ -60,7 +60,7 @@ exports.defineAutoTests = function () { }; // On Windows, some tests prompt user for permission to use geolocation and interrupt autotests run - var isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone); + var isWindowsStore = (cordova.platformId === 'windows8') || (cordova.platformId === 'windows' && !WinJS.Utilities.isPhone); // eslint-disable-line no-undef var majorDeviceVersion = null; var versionRegex = /(\d)\..+/.exec(device.version); if (versionRegex !== null) { @@ -68,29 +68,28 @@ exports.defineAutoTests = function () { } // Starting from Android 6.0 there are confirmation dialog which prevents us from running auto tests in silent mode (user interaction needed) // Also, Android emulator doesn't provide geo fix without manual interactions or mocks - var skipAndroid = cordova.platformId == "android" && (device.isVirtual || majorDeviceVersion >= 6); + var skipAndroid = cordova.platformId === 'android' && (device.isVirtual || majorDeviceVersion >= 6); // eslint-disable-line no-undef var isIOSSim = false; // if iOS simulator does not have a location set, it will fail. - describe('Geolocation (navigator.geolocation)', function () { - it("geolocation.spec.1 should exist", function () { + it('geolocation.spec.1 should exist', function () { expect(navigator.geolocation).toBeDefined(); }); - it("geolocation.spec.2 should contain a getCurrentPosition function", function () { + it('geolocation.spec.2 should contain a getCurrentPosition function', function () { expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined(); - expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true); + expect(typeof navigator.geolocation.getCurrentPosition === 'function').toBe(true); }); - it("geolocation.spec.3 should contain a watchPosition function", function () { + it('geolocation.spec.3 should contain a watchPosition function', function () { expect(typeof navigator.geolocation.watchPosition).toBeDefined(); - expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true); + expect(typeof navigator.geolocation.watchPosition === 'function').toBe(true); }); - it("geolocation.spec.4 should contain a clearWatch function", function () { + it('geolocation.spec.4 should contain a clearWatch function', function () { expect(typeof navigator.geolocation.clearWatch).toBeDefined(); - expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true); + expect(typeof navigator.geolocation.clearWatch === 'function').toBe(true); }); }); @@ -99,7 +98,7 @@ exports.defineAutoTests = function () { describe('error callback', function () { - it("geolocation.spec.5 should be called if we set timeout to 0 and maximumAge to a very small number", function (done) { + it('geolocation.spec.5 should be called if we set timeout to 0 and maximumAge to a very small number', function (done) { if (isWindowsStore || skipAndroid) { pending(); } @@ -113,14 +112,14 @@ exports.defineAutoTests = function () { }); }); - it("geolocation.spec.9 on failure should return PositionError object with error code constants", function (done) { + it('geolocation.spec.9 on failure should return PositionError object with error code constants', function (done) { if (isWindowsStore || skipAndroid) { pending(); } navigator.geolocation.getCurrentPosition( fail.bind(this, done), - function(gpsError) { + function (gpsError) { // W3C specs: http://dev.w3.org/geo/api/spec-source.html#position_error_interface expect(gpsError.PERMISSION_DENIED).toBe(1); expect(gpsError.POSITION_UNAVAILABLE).toBe(2); @@ -137,7 +136,7 @@ exports.defineAutoTests = function () { describe('success callback', function () { - it("geolocation.spec.6 should be called with a Position object", function (done) { + it('geolocation.spec.6 should be called with a Position object', function (done) { if (isWindowsStore || skipAndroid) { pending(); } @@ -146,14 +145,13 @@ exports.defineAutoTests = function () { expect(p.coords).toBeDefined(); expect(p.timestamp).toBeDefined(); done(); - }, function(err){ - if(err.message && err.message.indexOf('kCLErrorDomain') > -1){ - console.log("Error: Location not set in simulator, tests will fail."); + }, function (err) { + if (err.message && err.message.indexOf('kCLErrorDomain') > -1) { + console.log('Error: Location not set in simulator, tests will fail.'); expect(true).toBe(true); isIOSSim = true; done(); - } - else { + } else { fail(done); } }, @@ -167,10 +165,10 @@ exports.defineAutoTests = function () { describe('watchPosition method', function () { - beforeEach(function(done) { + beforeEach(function (done) { // This timeout is set to lessen the load on platform's geolocation services // which were causing occasional test failures - setTimeout(function() { + setTimeout(function () { done(); }, 100); }); @@ -182,7 +180,7 @@ exports.defineAutoTests = function () { navigator.geolocation.clearWatch(errorWatch); }); - it("geolocation.spec.7 should be called if we set timeout to 0 and maximumAge to a very small number", function (done) { + it('geolocation.spec.7 should be called if we set timeout to 0 and maximumAge to a very small number', function (done) { if (isWindowsStore || skipAndroid) { pending(); } @@ -197,7 +195,7 @@ exports.defineAutoTests = function () { }); }); - it("geolocation.spec.10 on failure should return PositionError object with error code constants", function (done) { + it('geolocation.spec.10 on failure should return PositionError object with error code constants', function (done) { if (isWindowsStore || skipAndroid) { pending(); } @@ -205,7 +203,7 @@ exports.defineAutoTests = function () { var context = this; errorWatch = navigator.geolocation.watchPosition( fail.bind(this, done, context, 'Unexpected win'), - function(gpsError) { + function (gpsError) { if (context.done) return; context.done = true; @@ -231,7 +229,7 @@ exports.defineAutoTests = function () { navigator.geolocation.clearWatch(successWatch); }); - it("geolocation.spec.8 should be called with a Position object", function (done) { + it('geolocation.spec.8 should be called with a Position object', function (done) { if (isWindowsStore || skipAndroid || isIOSSim) { pending(); } @@ -245,7 +243,7 @@ exports.defineAutoTests = function () { expect(p.coords).toBeDefined(); expect(p.timestamp).toBeDefined(); - // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach + // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach setTimeout(function () { done(); }); @@ -273,10 +271,10 @@ exports.defineManualTests = function (contentEl, createActionButton) { /** * Set location status */ - function setLocationStatus(status) { + function setLocationStatus (status) { document.getElementById('location_status').innerHTML = status; } - function setLocationDetails(p) { + function setLocationDetails (p) { var date = (new Date(p.timestamp)); document.getElementById('latitude').innerHTML = p.coords.latitude; document.getElementById('longitude').innerHTML = p.coords.longitude; @@ -285,19 +283,19 @@ exports.defineManualTests = function (contentEl, createActionButton) { document.getElementById('heading').innerHTML = p.coords.heading; document.getElementById('speed').innerHTML = p.coords.speed; document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy; - document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString(); + document.getElementById('timestamp').innerHTML = date.toDateString() + ' ' + date.toTimeString(); } /** * Stop watching the location */ - function stopLocation() { + function stopLocation () { var geo = navigator.geolocation; if (!geo) { - alert('navigator.geolocation object is missing.'); + alert('navigator.geolocation object is missing.'); // eslint-disable-line no-undef return; } - setLocationStatus("Stopped"); + setLocationStatus('Stopped'); if (watchLocationId) { geo.clearWatch(watchLocationId); watchLocationId = null; @@ -310,7 +308,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { var watchLocation = function () { var geo = navigator.geolocation; if (!geo) { - alert('navigator.geolocation object is missing.'); + alert('navigator.geolocation object is missing.'); // eslint-disable-line no-undef return; } @@ -321,13 +319,13 @@ exports.defineManualTests = function (contentEl, createActionButton) { // Fail callback var fail = function (e) { - console.log("watchLocation fail callback with error code " + e); + console.log('watchLocation fail callback with error code ' + e); stopLocation(geo); }; // Get location watchLocationId = geo.watchPosition(success, fail, { enableHighAccuracy: true }); - setLocationStatus("Running"); + setLocationStatus('Running'); }; /** @@ -336,7 +334,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { var getLocation = function (opts) { var geo = navigator.geolocation; if (!geo) { - alert('navigator.geolocation object is missing.'); + alert('navigator.geolocation object is missing.'); // eslint-disable-line no-undef return; } @@ -346,16 +344,16 @@ exports.defineManualTests = function (contentEl, createActionButton) { // Success callback var success = function (p) { setLocationDetails(p); - setLocationStatus("Done"); + setLocationStatus('Done'); }; // Fail callback var fail = function (e) { - console.log("getLocation fail callback with error code " + e.code); - setLocationStatus("Error: " + e.code); + console.log('getLocation fail callback with error code ' + e.code); + setLocationStatus('Error: ' + e.code); }; - setLocationStatus("Retrieving location..."); + setLocationStatus('Retrieving location...'); // Get location geo.getCurrentPosition(success, fail, opts || { enableHighAccuracy: true }); //, {timeout: 10000}); @@ -366,54 +364,54 @@ exports.defineManualTests = function (contentEl, createActionButton) { var location_div = '
' + 'Status: Stopped' + - '', - latitude = '' + + '
'; + var latitude = '' + '' + '' + '' + - '', - longitude = '' + + ''; + var longitude = '' + '' + '' + '' + - '', - altitude = '' + + ''; + var altitude = '' + '' + '' + '' + - '', - accuracy = '' + + ''; + var accuracy = '' + '' + '' + '' + - '', - heading = '' + + ''; + var heading = '' + '' + '' + '' + - '', - speed = '' + + ''; + var speed = '' + '' + '' + '' + - '', - altitude_accuracy = '' + + ''; + var altitude_accuracy = '' + '' + '' + '' + - '', - time = '' + + ''; + var time = '' + '' + '' + '' + '' + '
Latitude: (decimal degrees) geographic coordinate [#ref]
Longitude: (decimal degrees) geographic coordinate [#ref]
Altitude: null if not supported;
' + '(meters) height above the [WGS84] ellipsoid. [#ref]
Accuracy: (meters; non-negative; 95% confidence level) the accuracy level of the latitude and longitude coordinates. [#ref]
Heading: null if not supported;
' + 'NaN if speed == 0;
' + '(degrees; 0° ≤ heading < 360°) direction of travel of the hosting device- counting clockwise relative to the true north. [#ref]
Speed: null if not supported;
' + '(meters per second; non-negative) magnitude of the horizontal component of the hosting device current velocity. [#ref]
Altitude Accuracy: null if not supported;
(meters; non-negative; 95% confidence level) the accuracy level of the altitude. [#ref]
Time: (DOMTimeStamp) when the position was acquired [#ref]
' + - '
', - actions = + ''; + var actions = '
' + 'Expected result: Will update all applicable values in status box for current location. Status will read Retrieving Location (may not see this if location is retrieved immediately) then Done.' + '

' + @@ -421,10 +419,10 @@ exports.defineManualTests = function (contentEl, createActionButton) { '

' + 'Expected result: Will stop watching the location so values will not be updated. Status will read Stopped.' + '

' + - 'Expected result: Will update location values with a cached position that is up to 30 seconds old. Verify with time value. Status will read Done.', - values_info = - '

Details about each value are listed below in the status box

', - note = + 'Expected result: Will update location values with a cached position that is up to 30 seconds old. Verify with time value. Status will read Done.'; + var values_info = + '

Details about each value are listed below in the status box

'; + var note = '

Allow use of current location, if prompted

'; contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed + diff --git a/www/Coordinates.js b/www/Coordinates.js index 84fdd5b8..1d7e8794 100644 --- a/www/Coordinates.js +++ b/www/Coordinates.js @@ -30,7 +30,7 @@ * @param {Object} altacc * @constructor */ -var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { +var Coordinates = function (lat, lng, alt, acc, head, vel, altacc) { /** * The latitude of the position. */ diff --git a/www/Position.js b/www/Position.js index d6b2c0cc..b4f20e07 100644 --- a/www/Position.js +++ b/www/Position.js @@ -21,7 +21,7 @@ var Coordinates = require('./Coordinates'); -var Position = function(coords, timestamp) { +var Position = function (coords, timestamp) { if (coords) { this.coords = new Coordinates(coords.latitude, coords.longitude, coords.altitude, coords.accuracy, coords.heading, coords.velocity, coords.altitudeAccuracy); } else { diff --git a/www/PositionError.js b/www/PositionError.js index 94562407..476b322a 100644 --- a/www/PositionError.js +++ b/www/PositionError.js @@ -26,7 +26,7 @@ * @param code * @param message */ -var PositionError = function(code, message) { +var PositionError = function (code, message) { this.code = code || null; this.message = message || ''; }; diff --git a/www/android/geolocation.js b/www/android/geolocation.js index 7265bec0..54005545 100644 --- a/www/android/geolocation.js +++ b/www/android/geolocation.js @@ -19,7 +19,7 @@ * */ -var exec = cordova.require('cordova/exec'); +var exec = cordova.require('cordova/exec'); // eslint-disable-line no-undef var utils = require('cordova/utils'); var PositionError = require('./PositionError'); @@ -28,44 +28,44 @@ var PositionError = require('./PositionError'); var pluginToNativeWatchMap = {}; module.exports = { - getCurrentPosition: function(success, error, args) { - var win = function() { - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); - geo.getCurrentPosition(success, error, args); + getCurrentPosition: function (success, error, args) { + var win = function () { + var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); // eslint-disable-line no-undef + geo.getCurrentPosition(success, error, args); }; - var fail = function() { + var fail = function () { if (error) { - error(new PositionError (PositionError.PERMISSION_DENIED, 'Illegal Access')); + error(new PositionError(PositionError.PERMISSION_DENIED, 'Illegal Access')); } }; - exec(win, fail, "Geolocation", "getPermission", []); + exec(win, fail, 'Geolocation', 'getPermission', []); }, - watchPosition: function(success, error, args) { + watchPosition: function (success, error, args) { var pluginWatchId = utils.createUUID(); - var win = function() { - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); + var win = function () { + var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); // eslint-disable-line no-undef pluginToNativeWatchMap[pluginWatchId] = geo.watchPosition(success, error, args); }; - var fail = function() { + var fail = function () { if (error) { error(new PositionError(PositionError.PERMISSION_DENIED, 'Illegal Access')); } }; - exec(win, fail, "Geolocation", "getPermission", []); + exec(win, fail, 'Geolocation', 'getPermission', []); return pluginWatchId; }, - clearWatch: function(pluginWatchId) { - var win = function() { + clearWatch: function (pluginWatchId) { + var win = function () { var nativeWatchId = pluginToNativeWatchMap[pluginWatchId]; - var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); + var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); // eslint-disable-line no-undef geo.clearWatch(nativeWatchId); }; - exec(win, null, "Geolocation", "getPermission", []); + exec(win, null, 'Geolocation', 'getPermission', []); } }; diff --git a/www/blackberry10/GeolocationProxy.js b/www/blackberry10/GeolocationProxy.js deleted file mode 100644 index 0bba2263..00000000 --- a/www/blackberry10/GeolocationProxy.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 idsMap = {}, - geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation'); - -module.exports = { - - getLocation: function(success, error, args) { - var successCallback = function (result) { - var pos = result.coords; - pos.timestamp = result.timestamp; - if (success) { - success(pos); - } - }; - geo.getCurrentPosition(successCallback, error, { - enableHighAccuracy: args[0], - maximumAge: args[1] - }); - }, - - addWatch: function(success, error, args) { - var id = args[0], - successCallback = function (result) { - var pos = result.coords; - pos.timestamp = result.timestamp; - if (success) { - success(pos); - } - }, - nativeId = geo.watchPosition(successCallback, error, { - enableHighAccuracy: args[1] - }); - idsMap[id] = nativeId; - }, - - clearWatch: function(success, error, args) { - var id = args[0]; - if(id in idsMap) { - geo.clearWatch(idsMap[id]); - delete idsMap[id]; - } - if(success) { - success(); - } - } - -}; - -require("cordova/exec/proxy").add("Geolocation", module.exports); diff --git a/www/geolocation.js b/www/geolocation.js index f1f64456..c6c57884 100644 --- a/www/geolocation.js +++ b/www/geolocation.js @@ -19,16 +19,16 @@ * */ -var argscheck = require('cordova/argscheck'), - utils = require('cordova/utils'), - exec = require('cordova/exec'), - PositionError = require('./PositionError'), - Position = require('./Position'); +var argscheck = require('cordova/argscheck'); +var utils = require('cordova/utils'); +var exec = require('cordova/exec'); +var PositionError = require('./PositionError'); +var Position = require('./Position'); -var timers = {}; // list of timers in use +var timers = {}; // list of timers in use // Returns default params, overrides if provided with values -function parseParameters(options) { +function parseParameters (options) { var opt = { maximumAge: 0, enableHighAccuracy: false, @@ -55,20 +55,20 @@ function parseParameters(options) { } // Returns a timeout failure, closed over a specified timeout value and error callback. -function createTimeout(errorCallback, timeout) { - var t = setTimeout(function() { +function createTimeout (errorCallback, timeout) { + var t = setTimeout(function () { clearTimeout(t); t = null; errorCallback({ - code:PositionError.TIMEOUT, - message:"Position retrieval timed out." + code: PositionError.TIMEOUT, + message: 'Position retrieval timed out.' }); }, timeout); return t; } var geolocation = { - lastPosition:null, // reference to last known (cached) position returned + lastPosition: null, // reference to last known (cached) position returned /** * Asynchronously acquires the current position. * @@ -76,15 +76,15 @@ var geolocation = { * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL) * @param {PositionOptions} options The options for getting the position data. (OPTIONAL) */ - getCurrentPosition:function(successCallback, errorCallback, options) { + getCurrentPosition: function (successCallback, errorCallback, options) { argscheck.checkArgs('fFO', 'geolocation.getCurrentPosition', arguments); options = parseParameters(options); // Timer var that will fire an error callback if no position is retrieved from native // before the "timeout" param provided expires - var timeoutTimer = {timer:null}; + var timeoutTimer = {timer: null}; - var win = function(p) { + var win = function (p) { clearTimeout(timeoutTimer.timer); if (!(timeoutTimer.timer)) { // Timeout already happened, or native fired error callback for @@ -94,20 +94,20 @@ var geolocation = { } var pos = new Position( { - latitude:p.latitude, - longitude:p.longitude, - altitude:p.altitude, - accuracy:p.accuracy, - heading:p.heading, - velocity:p.velocity, - altitudeAccuracy:p.altitudeAccuracy + latitude: p.latitude, + longitude: p.longitude, + altitude: p.altitude, + accuracy: p.accuracy, + heading: p.heading, + velocity: p.velocity, + altitudeAccuracy: p.altitudeAccuracy }, p.timestamp ); geolocation.lastPosition = pos; successCallback(pos); }; - var fail = function(e) { + var fail = function (e) { clearTimeout(timeoutTimer.timer); timeoutTimer.timer = null; var err = new PositionError(e.code, e.message); @@ -123,8 +123,8 @@ var geolocation = { // If the cached position check failed and the timeout was set to 0, error out with a TIMEOUT error object. } else if (options.timeout === 0) { fail({ - code:PositionError.TIMEOUT, - message:"timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter." + code: PositionError.TIMEOUT, + message: "timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter." }); // Otherwise we have to call into native to retrieve a position. } else { @@ -139,7 +139,7 @@ var geolocation = { // always truthy before we call into native timeoutTimer.timer = true; } - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.maximumAge]); + exec(win, fail, 'Geolocation', 'getLocation', [options.enableHighAccuracy, options.maximumAge]); } return timeoutTimer; }, @@ -152,7 +152,7 @@ var geolocation = { * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL) * @return String The watch id that must be passed to #clearWatch to stop watching. */ - watchPosition:function(successCallback, errorCallback, options) { + watchPosition: function (successCallback, errorCallback, options) { argscheck.checkArgs('fFO', 'geolocation.getCurrentPosition', arguments); options = parseParameters(options); @@ -161,7 +161,7 @@ var geolocation = { // Tell device to get a position ASAP, and also retrieve a reference to the timeout timer generated in getCurrentPosition timers[id] = geolocation.getCurrentPosition(successCallback, errorCallback, options); - var fail = function(e) { + var fail = function (e) { clearTimeout(timers[id].timer); var err = new PositionError(e.code, e.message); if (errorCallback) { @@ -169,20 +169,20 @@ var geolocation = { } }; - var win = function(p) { + var win = function (p) { clearTimeout(timers[id].timer); if (options.timeout !== Infinity) { timers[id].timer = createTimeout(fail, options.timeout); } var pos = new Position( { - latitude:p.latitude, - longitude:p.longitude, - altitude:p.altitude, - accuracy:p.accuracy, - heading:p.heading, - velocity:p.velocity, - altitudeAccuracy:p.altitudeAccuracy + latitude: p.latitude, + longitude: p.longitude, + altitude: p.altitude, + accuracy: p.accuracy, + heading: p.heading, + velocity: p.velocity, + altitudeAccuracy: p.altitudeAccuracy }, p.timestamp ); @@ -190,7 +190,7 @@ var geolocation = { successCallback(pos); }; - exec(win, fail, "Geolocation", "addWatch", [id, options.enableHighAccuracy]); + exec(win, fail, 'Geolocation', 'addWatch', [id, options.enableHighAccuracy]); return id; }, @@ -199,11 +199,11 @@ var geolocation = { * * @param {String} id The ID of the watch returned from #watchPosition */ - clearWatch:function(id) { + clearWatch: function (id) { if (id && timers[id] !== undefined) { clearTimeout(timers[id].timer); timers[id].timer = false; - exec(null, null, "Geolocation", "clearWatch", [id]); + exec(null, null, 'Geolocation', 'clearWatch', [id]); } } };