mauron85/cordova-plugin-background-geolocation

Capacitor support

Closed this issue · 2 comments

note5 commented

I have gone through examples of how to use this plugin and i tried to adapt it to capacitor and vue js. I used the guidelines shown here to install capacitor plugins
I managed to build it by installing some other ionic packages that were required. I have opened it on android studio and I get the following logs

49 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Native: tried calling BackgroundGeolocation.configure, but the BackgroundGeolocation plugin is not installed.
2020-02-09 19:21:31.051 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Install the BackgroundGeolocation plugin: 'ionic cordova plugin add @mauron85/cordova-plugin-background-geolocation'
2020-02-09 19:21:31.053 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Native: tried calling BackgroundGeolocation.on, but the BackgroundGeolocation plugin is not installed.
2020-02-09 19:21:31.055 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Install the BackgroundGeolocation plugin: 'ionic cordova plugin add @mauron85/cordova-plugin-background-geolocation'
2020-02-09 19:21:31.077 2769-2769/com.example.vuecapacitordemo E/Capacitor/Console: File: capacitor-runtime.js - Line 359 - Msg: plugin_not_installed
2020-02-09 19:21:31.113 2769-3015/com.example.vuecapacitordemo E/Capacitor: JavaScript Error: {"type":"js.error","error":{"message":"Uncaught plugin_not_installed","url":"http://localhost/js/chunk-vendors.af84ea82.js","line":1,"col":6931,"errorObject":"\"plugin_not_installed\""}}
2020-02-09 19:21:31.117 2769-2769/com.example.vuecapacitordemo E/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Uncaught plugin_not_installed
2020-02-09 19:23:17.633 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Native: tried calling BackgroundGeolocation.start, but the BackgroundGeolocation plugin is not installed.
2020-02-09 19:23:17.635 2769-2769/com.example.vuecapacitordemo W/Capacitor/Console: File: http://localhost/js/chunk-vendors.af84ea82.js - Line 1 - Msg: Install the BackgroundGeolocation plugin: 'ionic cordova plugin add @mauron85/cordova-plugin-background-geolocation'<

My environment is:
plugin version "cordova-plugin-background-geolocation": "^1.0.6",
@ionic-native/background-geolocation": "^5.21.1",
android
windows OS
I am running it on Nokia 5 running android 9
Below is my package.json

__
{
"name": "vuecapacitordemo",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"@capacitor/android": "^1.5.0",
"@capacitor/cli": "^1.5.0",
"@capacitor/core": "^1.5.0",
"@ionic-native/background-geolocation": "^5.21.1",
"@ionic-native/core": "^5.21.1",
"axios": "^0.19.2",
"cordova-plugin-background-geolocation": "^1.0.6",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-geolocation": "^4.0.2",
"core-js": "^3.6.4",
"vue": "^2.6.11",
"vue-router": "^3.1.5",
"vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.2.0",
"@vue/cli-plugin-router": "~4.2.0",
"@vue/cli-plugin-vuex": "~4.2.0",
"@vue/cli-service": "~4.2.0",
"vue-template-compiler": "^2.6.11"
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
__
this is my script

`
import axios from "axios";
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationEvents, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation';
export default {
name: "Home",
data: () => {
return {
count: 1,
url: "http://192.168.100.33:3000/location"
};
},
mounted() {
try {
console.log(BackgroundGeolocation);

  BackgroundGeolocation.configure({
    locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
    desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
    stationaryRadius: 20,
    distanceFilter: 30,
    debug: true, //  enable this hear sounds for background-geolocation life-cycle.
    stopOnTerminate: false
  });

  BackgroundGeolocation.on("authorization", function(status) {
    console.log(
      "[INFO] BackgroundGeolocation authorization status: " + status
    );
    if (status !== BackgroundGeolocation.AUTHORIZED) {
      // we need to set delay or otherwise alert may not be shown
      setTimeout(function() {
        var showSettings = confirm(
          "App requires location tracking permission. Would you like to open app settings?"
        );
        if (showSettings) {
          return BackgroundGeolocation.showAppSettings();
        }
      }, 1000);
    }
  });
  BackgroundGeolocation.on(location).subscribe(location => {
    console.log(location);
    this.sendLocation(location);
  });
} catch (err) {
  console.log(err);
}

},
methods: {
start: function() {
BackgroundGeolocation.start();
},
stop: function() {
BackgroundGeolocation.stop();
},
sendLocation: async function(location) {
try {
let resp = await axios.post(this.url, location);
} catch (err) {
console.log(err);
}
}
}
};
</script>`

I would appreciate any guidance on this

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn't be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it's important. Thank you for your contributions.