Cordova 背景地理定位不起作用,未定义
我正在尝试将此插件用于IONIC1,并使用本页“自述”中提供的代码。当我在galaxy s7上编译和测试时,我遇到以下错误: 背景地理位置未定义 我正在使用以下代码:Cordova 背景地理定位不起作用,未定义,cordova,ionic-framework,cordova-plugins,Cordova,Ionic Framework,Cordova Plugins,我正在尝试将此插件用于IONIC1,并使用本页“自述”中提供的代码。当我在galaxy s7上编译和测试时,我遇到以下错误: 背景地理位置未定义 我正在使用以下代码: Android Device manufacturer and model: Samsung Galaxy s7 Cordova version: 8.0.0 cordova-android-play-services-gradle-release 1.4.2 "cordova-android-play-ser
Android
Device manufacturer and model: Samsung Galaxy s7
Cordova version: 8.0.0
cordova-android-play-services-gradle-release 1.4.2 "cordova-android-play-services-gradle-release"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-facebook4 2.1.0 "Facebook Connect"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-googlemaps 2.3.2 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-mauron85-background-geolocation 2.3.5 "CDVBackgroundGeolocation"
cordova-plugin-request-location-accuracy 2.2.3 "Request Location Accuracy"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova.plugins.diagnostic 4.0.8 "Diagnostic"
我错过了什么或者我做错了什么
cordova-plugin-mauron85-background-geolocation 2.3.5
您使用的是插件版本,而不是3.0
从第一代到第三代
backgroundGeolocation对象重命名为backgroundGeolocation
您可以将插件版本更新为最新版本
app.controller('loginController', function($scope,$timeout) {
function onDeviceReady() {
BackgroundGeolocation.configure({
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 50,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
debug: true,
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000,
url: 'http://192.168.81.15:3000/location',
httpHeaders: {
'X-FOO': 'bar'
},
// customize post properties
postTemplate: {
lat: '@latitude',
lon: '@longitude',
foo: 'bar' // you can also add your own properties
}
});
BackgroundGeolocation.on('location', function(location) {
// handle your locations here
// to perform long running operation on iOS
// you need to create background task
BackgroundGeolocation.startTask(function(taskKey) {
// execute long running task
// eg. ajax post location
// IMPORTANT: task has to be ended by endTask
BackgroundGeolocation.endTask(taskKey);
});
});
BackgroundGeolocation.on('stationary', function(stationaryLocation) {
// handle stationary locations here
});
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 (showSetting) {
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.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.events.forEach(function(event) {
// return BackgroundGeolocation.removeAllListeners(event);
// });
}
document.addEventListener('deviceready', onDeviceReady, false);
});
或
使用
我会选择第一个选项,因为迁移更改文档列出了许多突破性的更改。尝试并成功(正如@Suraj Rao在6月25日13:56建议的那样)
我不知道为什么我要使用2.x版,按照“cordova添加…”的说明,最新版本应该可以下载。我知道你非常了解这个插件。是否可以使用返回自定义结构的web服务来生成本地通知?谢谢。我知道你对这个插件非常了解,不是真的。。。我没有用过。做了一些谷歌搜索并发现了问题。我从错误消息中知道问题出在cordova插件全局对象上。您是否尝试了
ionic cordova插件添加cordova-plugin-mauron85-background-geolocation@latest
?我还不在家。但是当我到达的时候,我会试着通知你。如果你能给我一点指导,我将不胜感激。我需要背景地理定位,按照我说的做。我有一个点数组,如果用户靠近某个地方,就会生成一个本地通知。我需要这样做,但在ionic1上。我是这方面的新手,所以我没有太多经验。@Kapilsoni您是否尝试调用this.platform.ready()
?不知道
ionic cordova plugin rm cordova-plugin-mauron85-background-geolocation
ionic cordova plugin add cordova-plugin-mauron85-background-geolocation
backgroundGeolocation.configure({...})
cordova plugin add cordova-plugin-mauron85-background-geolocation@latest