angularjs 및 ionic이있는 phonegap 프로젝트의 Geolocation 백그라운드 프로세스 (https://github.com/christocracy/cordova-plugin-background-geolocation)에 문제가 있습니다. 프로세스가 잘 실행되고 있지만 때때로 멈출 수는 없습니다.
앱이 포 그라운드에서 실행되고 있으면 정상적으로 작동합니다. 하지만 배경 서비스를 시작한 다음 내 장치 (samsung galaxy s2)의 홈 버튼을 누르면 프로세스가 백그라운드에서 올바르게 실행됩니다. 이제 앱을 다시 열고 백그라운드 프로세스를 중지하려고 시도하지만 현재로서는 작동하지 않습니다.
내가 올바른 프로세스 인스턴스를 갖고 있지 않은 것으로 보입니다. 내가 LocationService.stop()를 응용 프로그램이 재개 된 후 호출하면anglejs 및 ionic이있는 phonegap에서 실행중인 백그라운드 프로세스에 대한 액세스
var bgGeo;
angular.module('starter.services', [])
.factory('LocationService', function($http, $location){
function startBackgroundLocation() {
var gpsOptions = {
enableHighAccuracy : true,
timeout: 10000,
maximumAge: 5000
};
navigator.geolocation.getCurrentPosition(function(location) {
console.log('Location from Phonegap');
},
function (error){
alert('error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
},gpsOptions);
bgGeo = window.plugins.backgroundGeoLocation;
/**
* This would be your own callback for Ajax-requests after POSTing background geolocation to your server.
*/
var yourAjaxCallback = function(response) {
////
// IMPORTANT: You must execute the #finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
//
//
bgGeo.finish();
};
/**
* This callback will be executed every time a geolocation is recorded in the background.
*/
var callbackFn = function(location) {
alert('[js] BackgroundGeoLocation callback: ' + location.latitudue + ',' + location.longitude);
// Do your HTTP request here to POST location to your server.
//
//
// This is never called in Android
yourAjaxCallback.call(this);
};
var failureFn = function(error) {
alert('BackgroundGeoLocation error');
}
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
url: apiUrl + '/position/', // <-- only required for Android; ios allows javascript callbacks for your http
params: { // HTTP POST params sent to your server when persisting locations.
auth_token: localStorage.getItem('gcmToken')
},
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
// wenn der Service bereits läuft, nicht mehr starten
bgGeo.start();
}
function stopBackgroundLocation(){
bgGeo.stop();
}
return {
start: function(){
init();
},
stop : function() {
stopBackgroundLocation();
}
}
}
, 배경 위치 정보는 멈추지 않는다 :
이 내 코드입니다.
누군가가 잘못되었거나 내가 추가해야하는 것을 알고 있습니까? 감사.
@Aleks : 아마도 해결책을 알고 있습니까?
지금은 해결책이나 힌트가 있습니까? 이것이 내 시험을위한 것이기 때문에 이것은 정말로 수입입니다. 고맙습니다! – sbr11