简体   繁体   中英

Cordova - how do I know if my app is using the HTML5 Geolocation API or the cordova geolocation plugin?

I am developing an Angular 1.5.3/Cordova 6.5/Ionic 1.3.3 App. In my app I intend to use the cordova geo-location plugin. The app will run in WebView (usually Chrome Stable on Android).

Here is my package.json file:

{
  "name": "myApp",
  "description": "yadda",
  "version": "4.2.0",
  "private": true,
  "dependencies": {
    "angular": "1.5.3"
  },
  "devDependencies": {
  },
  "cordovaPlugins": [
    "cordova-plugin-network-information@1.2.1",
    "cordova-plugin-geolocation@2.2.0"
  ]
}

I notice that there is an HTML5 API to detect geolocation: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition

I also notice a cordova plugin (that I have added to my plugins): https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/index.html

The syntax for both of the libraries is identical:

navigator.geolocation.getCurrentPosition

How can I be sure that my app is using the plugin version?

The cordova-plugin-geolocation for Android only have code to handle the permissions needed on Android 6 and newer. If you don't install the plugin, the geolocation won't work on Android 6 or newer. Other than that, it uses the webview implementation.

On iOS it uses native code. If you don't install the plugin it uses the webview implementation, you can notice the plugin is not installed as it will show "index.html wants to access your location" instead of "yourAppName wants to access your location"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM