我试图导入一个cordova插件(https://www.npmjs.com/package/cordova-plugin-mauron85-background-geolocation)。我导入了它:
import {BackgroundGeolocation} from 'ionic-native';
并称之为:
BackgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
interval: 60000
});
但这会引发一个错误:提供的参数与调用目标的任何签名都不匹配 ...我知道这个错误意味着什么,但这是来自docs的一个例子......
答案 0 :(得分:1)
@ Patrick1870,如果您使用离子原生背景地理定位,configure方法将返回一个承诺。您的语法应如下所示。
import {BackgroundGeolocation} from 'ionic-native';
let backgroundOptions = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
locationTimeout: 60000 //interval is renamed to locationTimeout
};
BackgroundGeolocation.configure(backgroundOptions).then((location) => {
console.log("location", location)
}).catch((err) => console.log("Error ", err));
如果直接使用不带离子原生的插件,则必须将其用作
declare var backgroundGeolocation: any;
let backgroundOptions = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
locationTimeout: 60000 //interval is renamed to locationTimeout
};
backgroundGeolocation.configure((location) => {
console.log(location);
},(err) => {
console.log("error on background Geolocation ", err);
}, backgroundOptions);