2014-05-14 2 views
1

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 문서를 찾았지만 어디에 넣어야하는지 이해하지 못해 누군가가 도와 주면 도움이 될 수 있습니다.

+0

중요한 단어는 '지역'입니다. 나는'phonegap local plugin '에 https : // github.com/christocracy/cordova-plugin-background-geolocation.git을 추가하면 문제가 있다는 것을 알았고 대답을 게시 할 것입니다. 덕분에 지금은 – Aleks

답변

2

확인. 나는 대답을 찾았다.

중요한 단어는 local입니다. 플러그인은 local 단어로 설치해야합니다 : 예상대로

phonegap local plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git 

지금까지, 폰갭 3.3에 완벽하게 모두를 만들었습니다. 플러그인의 웹 사이트에서 자세한 지침을 따르십시오. 부수적으로, Angular.js를 사용하는 경우 일부 서비스 내에서 이것을 사용하려면 종속성 목록에 '$ window'를 추가하십시오. 예 :

angular 
.factory('Auth', [ '$http','$q', '$window', '$rootScope', '$location', 'Application', 'Service', function($http,$q, $window, $rootScope, $location, Application, Service){ 
// Some code and then: 

function callbackFn(){ 
//callback for ios 
} 

function failureFn(){ 
//callback for ios 
} 


function connect(){ 
    var bgGeo = $window.plugins.backgroundGeoLocation; 

    bgGeo.configure(callbackFn, failureFn, { 
        url: "www.yoursite.com/api/location_saver.json", 
        params: {  // HTTP POST params sent to your server when persisting locations. It will be posted to your server as is , so you can set any parameter you want 
         user_credentials: "aS9393498asdFfaSDF", 
         parameter2: "another parameter value I want to send" 
        }, 
        desiredAccuracy: 10, 
        stationaryRadius: 1, 
        distanceFilter: 1, 
        debug: true // <-- enable this hear sounds for background-geolocation life-cycle. 
       }); 


    bgGeo.start(); 
    } 
} 
+0

어디 지리적 위치를 보내려면 아약스 함수를 작성하려면 –

0

cordova_plugin.js에서 플러그인 구성을 선언하십시오.

cordova.define('cordova/plugin_list', function(require, exports, module) { 
    module.exports = [{ 
     "file": "plugins/cordova-plugin-background-geolocation/www/xxx.js", 
     "id": "cordova-plugin-background-geolocation", 
     "merges": ["window.plugins.backgroundGeoLocation"] 
    }]; 
    module.exports.metadata = // TOP OF METADATA 
    { 
     "cordova-plugin-background-geolocation": "0.0.0" 
    } 
}); 
+0

시험해보고 있지만 이미 정의되어 있습니다. 거기에 문제 없습니다. 또한'cordova_plugins.js '라고도합니다. 덕분에 어떤 경우 에든 – Aleks

관련 문제