Stackoverflow에서 비슷한 질문을 발견했지만 모두 내 질문 중 하나에 대답하지만 실제로 알지 못하는 것들이 많이 있습니다.Android 용 PhoneGap Background location plugin을 설치하는 방법은 무엇입니까?
내 PhoneGap 3.3.0 응용 프로그램에 지리적 위치 플러그인을 사용하고 싶었습니다. 나는 주소에 플러그인을 사용하고 싶었다. cordova-plugin-background-geolocation
좋아, 설치는 plugman과 함께 사용할 수 있다고 말한다. 그래서 나는 plugman을 설치했고, plugman을 설치했다. (phonegap plugin plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git
을 사용함에 따라 cordova 대신 phonegap을 설치했습니다.) 내가 폰갭을 구축하고 배포 할 때
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady() {
alert('Device ready');
//
// after deviceready
//
//
var bgGeo = window.plugins.backgroundGeoLocation;
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http
authToken: 'user_secret_auth_token', // <-- only required for Android; ios allows javascript callbacks for your http
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.
bgGeo.start();
}
// Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation,
// in order to prompt the user for Location permission.
window.navigator.geolocation.getCurrentPosition(function(location) {
console.log('Location from Phonegap');
alert("Get current location");
});
/**
* 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.
//
//
alert("Callback function");
//bgGeo.finish();
};
/**
* This callback will be executed every time a geolocation is recorded in the background.
*/
var callbackFn = function(location) {
console.log('[js] BackgroundGeoLocation callback: ' + location.latitudue + ',' + location.longitude);
// Do your HTTP request here to POST location to your server.
//
//
//yourAjaxCallback.call(this);
alert("Location recorded");
};
var failureFn = function(error) {
console.log('BackgroundGeoLocation error');
alert("BackgroundGeoLocation error");
}
// If you wish to turn OFF background-tracking, call the #stop method.
// bgGeo.stop()
</script>
: 그래서, 좋아, 새로운 자바 코드는 이제 /platforms/android/src/com/tenforwardconsulting/cordova/bgloc/BackgroundGpsPlugin.java
에 배치됩니다 내 index.html
로 (플러그인에서 말했듯이 기본적으로 동일)이 코드를 넣어 가지고 Android 휴대 전화 나는 '기기 준비'알림 만 받지만 내가 알지 못하는 다른 알림 (모든 위치에 알림을 표시하여 테스트 할 수 있음을 알 수 있습니다)
두 개의 질문.
이 플러그인도 PhoneGap 3.3.0과 호환 가능합니까? 어떻게 확인할 수 있습니까? 나는이 플러그인 실행 가능한 (plugin.xml에, config.xml 파일 등)로 wath 값을 만들기 위해 업데이트 할 필요가 어떤 파일 phonegap plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git
와 플러그인을 설치 제외
2. gap:plugin
을 추가하는 방법에 대한 설명서를 보았습니다. 그러나 제 컴파일러는 불평합니다. 그래서 일반적으로 이것을 작동시키기 위해 무엇을해야합니까?
중요하지만,이 플러그인을 사용하는 것에 대해 here 문서를 찾았지만 어디에 넣어야하는지 이해하지 못해 누군가가 도와 주면 도움이 될 수 있습니다.
중요한 단어는 '지역'입니다. 나는'phonegap local plugin '에 https : // github.com/christocracy/cordova-plugin-background-geolocation.git을 추가하면 문제가 있다는 것을 알았고 대답을 게시 할 것입니다. 덕분에 지금은 – Aleks