@antonsr98
Системный Администратор

Как выполнить пример Cordova Geolocation Background?

День Добрый, в плане разработки я нуб. Не буду этого скрывать. Хочу написать небольшое приложения для саморазвития. За основу проекта взял Apache Cordova. Хочу запустить background geolocation и поэтому выбрал plugin https://www.npmjs.com/package/cordova-plugin-mauro... . Но не могу понять как выполнить оттуда простейший example:
document.addEventListener('deviceready', onDeviceReady, false);
 
function onDeviceReady () {
 
    /**
    * This callback will be executed every time a geolocation is recorded in the background.
    */
    var callbackFn = function(location) {
        console.log('[js] BackgroundGeoLocation callback:  ' + location.latitude + ',' + location.longitude);
 
        // Do your HTTP request here to POST location to your server. 
        // jQuery.post(url, JSON.stringify(location)); 
 
        /*
        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.
        */
        backgroundGeoLocation.finish();
    };
 
    var failureFn = function(error) {
        console.log('BackgroundGeoLocation error');
    };
 
    // BackgroundGeoLocation is highly configurable. See platform specific configuration options 
    backgroundGeoLocation.configure(callbackFn, failureFn, {
        desiredAccuracy: 10,
        stationaryRadius: 20,
        distanceFilter: 30,
        debug: true, // <-- enable this hear sounds for background-geolocation life-cycle. 
        stopOnTerminate: false, // <-- enable this to clear background location settings when the app terminates 
    });
 
    // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app. 
    backgroundGeoLocation.start();
 
    // If you wish to turn OFF background-tracking, call the #stop method. 
    // backgroundGeoLocation.stop(); 
}


Подскажите плз куда вставить этот кусочек кода?
  • Вопрос задан
  • 541 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы