如何重复地理定位过程?

时间:2015-05-10 18:21:19

标签: cordova geolocation ionic

我正在尝试使用插件cordova-background-geolocation

angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicLoading, $ionicPlatform, $rootScope, $cordovaBackgroundGeolocation) {

    $ionicPlatform.ready(function() {
        if(window.StatusBar) {
          StatusBar.styleDefault();
        }

        // Geolocation
        window.navigator.geolocation.getCurrentPosition(function(location) {
        console.log(location);
        });

        var bgGeo = window.plugins.backgroundGeoLocation;

        var yourAjaxCallback = function(response) {
            console.log("You must execute the #finish method here");
            bgGeo.finish();
        };

        var callbackFn = function(location) {
            console.log('[js] BackgroundGeoLocation callback:  ' + location.latitude + ',' + location.longitude);
            // Do your HTTP request here to POST location to your server.
            yourAjaxCallback.call(this);
    };

        var failureFn = function(error) {
            console.log('BackgroundGeoLocation error');
        }

        bgGeo.configure(callbackFn, failureFn, {
            desiredAccuracy: 10,
            stationaryRadius: 20,
            distanceFilter: 30,
            activityType: 'AutomotiveNavigation',
            debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
            stopOnTerminate: false // <-- enable this to clear background location settings when the app terminates
        });
        bgGeo.start();
    });
})

当应用程序在调试模式下处于后台时,声音提醒我该应用程序试图获取位置。 但是当我移动时,日志输出中没有任何内容。

  

015-05-10 20:09:16.542 Icram [184:3192] CDVBackgroundGeoLocation configure

     

...行显示插件参数(distancefilter等)。

     

2015-05-10 20:09:16.545 Icram [184:3192] - CDVBackgroundGeoLocation start(background?0)

     

2015-05-10 20:09:16.557 Icram [184:3192]线程警告:['BackgroundGeoLocation']花了'11 .674805'ms。插件应该使用后台线程。

     

2015-05-10 20:09:36.008 Icram [184:3192] - CDVBackgroundGeoLocation暂停(已启用?1)

     

2015-05-10 20:09:36.009 Icram [184:3192] - CDVBackgroundGeoLocation setPace 0,stationaryRegion? 0

     

2015-05-10 20:09:36.176 Icram [184:3192] - CDVBackgroundGeoLocation didUpdateLocations(isMoving:0)

     

2015-05-10 20:09:36.178 Icram [184:3192] - CDVBackgroundGeoLocation didUpdateLocations(isMoving:0)

     

2015-05-10 20:09:36.178 Icram [184:3192] - 获取固定位置,准确度:65.000000

     

2015-05-10 20:09:36.180 Icram [184:3192] - CDVBackgroundGeoLocation didUpdateLocations(isMoving:0)

     

2015-05-10 20:09:36.181 Icram [184:3192] - 获取固定位置,准确度:65.000000

     

2015-05-10 20:09:36.182 Icram [184:3192] - CDVBackgroundGeoLocation didUpdateLocations(isMoving:0)

     

2015-05-10 20:09:36.182 Icram [184:3192] - 获取固定位置,准确度:65.000000

     

2015-05-10 20:09:36.182 Icram [184:3192] - CDVBackgroundGeoLocation didUpdateLocations(isMoving:0)

     

2015-05-10 20:09:36.183 Icram [184:3192] - 获取固定位置,准确度:65.000000

     

2015-05-10 20:09:36.186 Icram [184:3192] - CDVBackgroundGeoLocation createStationaryRegion(48.54 ....,2.67 ....)

     

2015-05-10 20:09:36.222 Icram [184:3585]职位:48.54 ....,2.67 ....,速度:-1.000000

     

2015-05-10 20:09:36.235 Icram [184:3192] [js] BackgroundGeoLocation回调:48.54 ....,2.67 ....

     

2015-05-10 20:12:33.221 Icram [184:3192] - CDVBackgroundGeoLocation stopBackgroundTask(剩余时间:3.994620)

你能解释一下如何使用插件,就像在github的例子中显示的那样吗?

0 个答案:

没有答案