Я пытаюсь добавить плагин @ mauron85 / cordova-plugin-background-geolocation в мой проект Angular9 + Cordova (не Ioni c). Я установил плагин Cordova и плагин NPM. Я добавил плагин в свой проект с помощью
import {BackgroundGeolocationPlugin} from '@mauron85/cordova-plugin-background-geolocation';
, сейчас я просто попытался заставить его работать со следующим в моем файле Main.ts
const bootstrap = () => {
console.log("Platform is Android or IOS")
var backgroundGeolocation: BackgroundGeolocationPlugin;
backgroundGeolocation.configure({
locationProvider: backgroundGeolocation.DISTANCE_FILTER_PROVIDER,
desiredAccuracy: backgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 5,
distanceFilter: 5,
notificationTitle: 'SOF-Background Location',
notificationText: 'enabled',
debug: true,
interval: 60000,
fastestInterval: 10000,
activitiesInterval: 10000,
url: 'http://192.168.81.15:3000/location',
// customize post properties
postTemplate: {
lat: '@latitude',
lon: '@longitude',
}
});
backgroundGeolocation.on('location', function(location) {
console.log(location)
});
backgroundGeolocation.on('error', function(error) {
console.log('[ERROR] BackgroundGeolocation error:', error.code, error.message);
});
backgroundGeolocation.on('start', function() {
console.log('[INFO] BackgroundGeolocation service has been started');
});
backgroundGeolocation.on('stop', function() {
console.log('[INFO] BackgroundGeolocation service has been stopped');
});
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('background', function() {
console.log('[INFO] App is in background');
// you can also reconfigure service (changes will be applied immediately)
backgroundGeolocation.configure({ debug: true });
});
backgroundGeolocation.on('foreground', function() {
console.log('[INFO] App is in foreground');
backgroundGeolocation.configure({ debug: false });
});
backgroundGeolocation.on('abort_requested', function() {
console.log('[INFO] Server responded with 285 Updates Not Required');
// Here we can decide whether we want stop the updates or not.
// If you've configured the server to return 285, then it means the server does not require further update.
// So the normal thing to do here would be to `BackgroundGeolocation.stop()`.
// But you might be counting on it to receive location updates in the UI, so you could just reconfigure and set `url` to null.
});
backgroundGeolocation.on('http_authorization', () => {
console.log('[INFO] App needs to authorize the http requests');
});
backgroundGeolocation.checkStatus(function(status) {
console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);
// you don't need to check status before start (this is just the example)
if (!status.isRunning) {
backgroundGeolocation.start(); //triggers start on start event
}
});
// you can also just start without checking for status
// BackgroundGeolocation.start();
// Don't forget to remove listeners at some point!
// BackgroundGeolocation.removeAllListeners();
platformBrowserDynamic().bootstrapModule(AppModule);
};
if (typeof window["cordova"] !== "undefined") {
document.addEventListener(
"deviceready",
() => {
bootstrap();
},
false
);
} else {
platformBrowserDynamic().bootstrapModule(AppModule);
}
Но каждый раз, когда я пытаюсь запустить Android App я получаю следующую консольную ошибку:
Uncaught TypeError: Cannot read property 'configure' of undefined
at bootstrap (main.ts:15)