christocracy / cordova-plugin-background-geolocation

Sophisticated, battery-conscious, cross-platform background-geolocation with motion-detection
http://transistorsoft.github.io/cordova-background-geolocation
492 stars 743 forks source link

bgGeo.start iOS not working any time #248

Closed chrigu89 closed 8 years ago

chrigu89 commented 8 years ago

I have a problem since month which a i cant fix... I made a bgGeo 1:1 like your description, but its only working on Android.

Below you find the fullcode. On iOS i didnt reseive any altert - not from the callbackFn or from the failureFn. Did i miss anything?

Thank you for your help!

` navigator.geolocation.getCurrentPosition(onSuccess, onError);

    var bgGeo = window.plugins.backgroundGeoLocation;

    var callbackFn = function(location) {
        alert('[js] BackgroundGeoLocation callback:  ' + location.latitudue + ',' + location.longitude);
        var token = window.localStorage.getItem("token");
        $.ajax({
            type: 'GET',
            url: 'http://.com/ios/api.php?rquest=set_device_geo',
            data:  { token: token, lat: location.latitude, long: location.longitude },
            crossDomain: true,
            cache: false,
            success: function(response) {
                bgGeo.finish();
            }
        });

        alert('BackgroundGeoLocation success');

    };

    var failureFn = function(error) {
        alert('BackgroundGeoLocation error');
        alert(error);
    }

    bgGeo.configure(callbackFn, failureFn, {
        url: 'http://.com/ios/api.php?rquest=set_device_geo', // <-- Android ONLY: your server url to send locations to
        params: {
            token: window.localStorage.getItem("token"),
        },
        method: 'GET',
        autoSync: true,
        locationUpdateInterval: 5000,
        desiredAccuracy: 0,
        stationaryRadius: 50,
        distanceFilter: 50,     
        activityType: 'AutomotiveNavigation',
        debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
    });

    bgGeo.start();

    //changePace(isMoving, callbackFn, failureFn);
}`
christocracy commented 8 years ago

Show me ios logs of the plugin booting.

On Thu, Feb 11, 2016 at 8:20 AM, chrigu89 notifications@github.com wrote:

I have a problem since month which a i cant fix... I made a bgGeo 1:1 like your description, but its only working on Android.

Below you find the fullcode. On iOS i didnt reseive any altert - not from the callbackFn or from the failureFn. Did i miss anything?

Thank you for your help!

` navigator.geolocation.getCurrentPosition(onSuccess, onError);

var bgGeo = window.plugins.backgroundGeoLocation;

var callbackFn = function(location) {
    alert('[js] BackgroundGeoLocation callback:  ' + location.latitudue + ',' + location.longitude);
    var token = window.localStorage.getItem("token");
    $.ajax({
        type: 'GET',
        url: 'http://ada-go.com/ios/api.php?rquest=set_device_geo',
        data:  { token: token, lat: location.latitude, long: location.longitude },
        crossDomain: true,
        cache: false,
        success: function(response) {
            bgGeo.finish();
        }
    });

    alert('BackgroundGeoLocation success');

};

var failureFn = function(error) {
    alert('BackgroundGeoLocation error');
    alert(error);
}

bgGeo.configure(callbackFn, failureFn, {
    url: 'http://ada-go.com/ios/api.php?rquest=set_device_geo', // <-- Android ONLY: your server url to send locations to
    params: {
        token: window.localStorage.getItem("token"),
    },
    method: 'GET',
    autoSync: true,
    locationUpdateInterval: 5000,
    desiredAccuracy: 0,
    stationaryRadius: 50,
    distanceFilter: 50,
    activityType: 'AutomotiveNavigation',
    debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
});

bgGeo.start();

//changePace(isMoving, callbackFn, failureFn);

}`

— Reply to this email directly or view it on GitHub https://github.com/christocracy/cordova-plugin-background-geolocation/issues/248 .

Chris Scott Transistor Software http://www.transistorsoft.com

chrigu89 commented 8 years ago

Where / How can i get the logs? Thanks!

christocracy commented 8 years ago

Boot App in XCode Boot app in XCode

Or view XCode->Window->Devices->[Your Device] XCode->Window->Devices

chrigu89 commented 8 years ago

I create the app with Phonegap Build and install it to my ipad, dont use xCode, sorry.

christocracy commented 8 years ago

I suggest you google "how do I get phonegap ios logs"

On Thu, Feb 11, 2016 at 11:01 AM, chrigu89 notifications@github.com wrote:

I create the app with Phonegap Build and install it to my ipad, dont use xCode, sorry.

— Reply to this email directly or view it on GitHub https://github.com/christocracy/cordova-plugin-background-geolocation/issues/248#issuecomment-182934329 .

Chris Scott Transistor Software http://www.transistorsoft.com

chrigu89 commented 8 years ago

There is no helpfull information, to create any logfile. They are all talking about console.log() which is not helpfull at all.

christocracy commented 8 years ago

That's no good.

On Thu, Feb 11, 2016 at 11:26 AM, chrigu89 notifications@github.com wrote:

There is no helpfull information, to create any logfile. They are all talking about console.log() which is not helpfull at all.

— Reply to this email directly or view it on GitHub https://github.com/christocracy/cordova-plugin-background-geolocation/issues/248#issuecomment-182943029 .

Chris Scott Transistor Software http://www.transistorsoft.com

chrigu89 commented 8 years ago

Hm possible for your, if i send post the git?

karolszklarski commented 8 years ago

Same thing here. No response from both callbackFn and failureFn. After start() nothing happens. I run it on real device (iPhone 5C), compiling cordova on remote mac, so can't provide logs too. Could you modify your plugin to output debug logs on js console?

christocracy commented 8 years ago

Are you aware that when you first start the plugin, it enters its "stationary" state. Try running the app in Xcode simulator and simulate location with "highway drive".

To test on a real device, you need to move typically 2-3 blocks to trigger out of stationary state

On Friday, February 12, 2016, karolszklarski notifications@github.com wrote:

Same thing here. No response from both callbackFn and failureFn. After start() nothing happens. I run in on real device (iPhone 5C), via cordova, compiling on remote mac, so can't provide logs too. Could you modify your plugin to output debug logs on js console?

— Reply to this email directly or view it on GitHub https://github.com/christocracy/cordova-plugin-background-geolocation/issues/248#issuecomment-183295329 .

Snet form Gmail Mobile

karolszklarski commented 8 years ago

I created a new cordova out-of-a-box project, installed minimal required plugins, added configure and start in onDeviceReady and then it works. GPS icon shows up in status bar and I start to receive locations. The config is { desiredAccuracy: 0, stationaryRadius: 20, distanceFilter: 10}

So there's clearly something wrong on my side. I also noticed that in this minimal project navigator.geolocation.watchPosition started to work in background and even setInterval() works in background too. In my "big" project none of these work in background.

I'll write more when I'll find out what's the problem.

christocracy commented 8 years ago

Be careful if you're using standard cordova-plugin-geolocation (which you don't require when using my plugin) -- don't allow watchPosition to run in the background or you'll kill the battery. watchPosition is fine for the foreground only.

christocracy commented 8 years ago

Also, when in doubt, boot the SampleApp.

chrigu89 commented 8 years ago

Hm i cant get any good result. Is there anyone, who can help me, fix that? I'll truly pay for it - its very important to me!

christocracy commented 8 years ago

This repo is no longer supported. Go here.

karolszklarski commented 8 years ago

Below is my current working code. I use forceBgGeoMoving() to start recording immediately. Without it I have to move a few hundred meters (until cell tower change, I suppose). onResume and onPause are "just in case".

document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("pause", onPause, false);

function onDeviceReady() {
    backgroundGeoLocation.configure(bgLocCallback, fail, {
        desiredAccuracy: 0,
        stationaryRadius: 20,
        distanceFilter: 10,
        activityType: 'Fitness',
        locationTimeout: 10,
        interval: 10000,
        fastestInterval: 1000,
        activitiesInterval: 20000,
        notificationTitle: 'TripTrack',
        notificationText: 'Recording trip',
        notificationIcon: 'notification_icon',
        locationService: backgroundGeoLocation.service.ANDROID_DISTANCE_FILTER,
        stopOnTerminate: true
    });
}

function onResume() {
    logInfo("onResume");
    if (recording) {
        forceBgGeoMoving();
    }
}

function onPause() {
    logInfo("onPause");
    if (recording) {
        forceBgGeoMoving();
    }
}

function fail(error) {
    // do something
}

function startGeoLocationBg() {
    backgroundGeoLocation.start();
    getCurrentLoc();
    forceBgGeoMoving();
}

function stopGeoLocationBg() {
    backgroundGeoLocation.stop();
}

function forceBgGeoMoving() {
    backgroundGeoLocation.changePace(true, function() {}, silentFail);
}

function bgLocCallback(location) {
    logInfo("bgLocCallback " + JSON.stringify(location));
    var loc = {
        coords: {
            latitude: location.latitude,
            longitude: location.longitude,
            accuracy: location.accuracy
        },
        timestamp: new Date(location.timestamp)
    };
    saveGpsPoint(loc);
    backgroundGeoLocation.finish();
}

function getCurrentLoc() {
    logInfo("getCurrentLoc");
    navigator.geolocation.getCurrentPosition(function(location) {
        saveGpsPoint(location);
    }, fail, { enableHighAccuracy: true });
}

function saveGpsPoint(location) {
    // do something
}