Get working Ionic + ngCordova + background geolocation
up vote
4
down vote
favorite
Goal of the app: get geolocation on each move and log location either when app is in foreground and background.
I've tried so many code and combination but I can't manage to have it working (2 days from now...).
The classic geolocation (getCurrentPosition) is working fine but when we close the app the background geolocation is launched but nothing happen... Function "callbackFn" is never fired.
I'm testing on IOS with xcode > Capabilities Audio & location activated for background activity. I also made working the jQuery sample example given in plugin so I saw it working but never with ionic/angularjs.
Here is the current controller handling the background:
.controller('TestCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window)
$scope.lat_geo = "loading lat...";
$scope.long_geo = "loading long...";
//-- Geolocal launch
var options =
enableHighAccuracy : false,
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 5,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
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
;
$ionicPlatform.ready(function()
console.log("[IONIC PLATFORM IS NOW READY]");
//-- First launch a basic geolocalisation to get user acceptance of geosharing ;)
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS1] Location from Phonegap');
,
function (error)
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
//-- test adaptation depuis l'app jquery
var callbackFn = function(location)
console.log('[BackgroundGeoLocation] Update callback: ' + location.latitude + ',' + location.longitude);
;
var failureFn = function(error)
console.log('[BackgroundGeoLocation] Error: '+error);
;
$cordovaBackgroundGeolocation.configure(callbackFn, failureFn, options);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
$cordovaBackgroundGeolocation.start();
//-- Just a timeout to retreive long / lat
$timeout(function()
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS3] Location from Phonegap');
startPos = location;
$scope.$apply(function ()
$scope.lat_geo = startPos.coords.latitude;
$scope.long_geo = startPos.coords.longitude;
);
console.log("[GEOLOCAL BASIC] OK this time :)");
,
function (error)
console.log('[GEOLOCAL JS3] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
, 3000);
);
//-- End Geolocal
)
I've put all my code (a complete ionic app starter) on github: https://github.com/Jeff86/ionic_ngcordova_backgroundgeo_test/tree/master
ios angularjs geolocation ionic-framework ngcordova
add a comment |
up vote
4
down vote
favorite
Goal of the app: get geolocation on each move and log location either when app is in foreground and background.
I've tried so many code and combination but I can't manage to have it working (2 days from now...).
The classic geolocation (getCurrentPosition) is working fine but when we close the app the background geolocation is launched but nothing happen... Function "callbackFn" is never fired.
I'm testing on IOS with xcode > Capabilities Audio & location activated for background activity. I also made working the jQuery sample example given in plugin so I saw it working but never with ionic/angularjs.
Here is the current controller handling the background:
.controller('TestCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window)
$scope.lat_geo = "loading lat...";
$scope.long_geo = "loading long...";
//-- Geolocal launch
var options =
enableHighAccuracy : false,
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 5,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
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
;
$ionicPlatform.ready(function()
console.log("[IONIC PLATFORM IS NOW READY]");
//-- First launch a basic geolocalisation to get user acceptance of geosharing ;)
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS1] Location from Phonegap');
,
function (error)
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
//-- test adaptation depuis l'app jquery
var callbackFn = function(location)
console.log('[BackgroundGeoLocation] Update callback: ' + location.latitude + ',' + location.longitude);
;
var failureFn = function(error)
console.log('[BackgroundGeoLocation] Error: '+error);
;
$cordovaBackgroundGeolocation.configure(callbackFn, failureFn, options);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
$cordovaBackgroundGeolocation.start();
//-- Just a timeout to retreive long / lat
$timeout(function()
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS3] Location from Phonegap');
startPos = location;
$scope.$apply(function ()
$scope.lat_geo = startPos.coords.latitude;
$scope.long_geo = startPos.coords.longitude;
);
console.log("[GEOLOCAL BASIC] OK this time :)");
,
function (error)
console.log('[GEOLOCAL JS3] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
, 3000);
);
//-- End Geolocal
)
I've put all my code (a complete ionic app starter) on github: https://github.com/Jeff86/ionic_ngcordova_backgroundgeo_test/tree/master
ios angularjs geolocation ionic-framework ngcordova
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Goal of the app: get geolocation on each move and log location either when app is in foreground and background.
I've tried so many code and combination but I can't manage to have it working (2 days from now...).
The classic geolocation (getCurrentPosition) is working fine but when we close the app the background geolocation is launched but nothing happen... Function "callbackFn" is never fired.
I'm testing on IOS with xcode > Capabilities Audio & location activated for background activity. I also made working the jQuery sample example given in plugin so I saw it working but never with ionic/angularjs.
Here is the current controller handling the background:
.controller('TestCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window)
$scope.lat_geo = "loading lat...";
$scope.long_geo = "loading long...";
//-- Geolocal launch
var options =
enableHighAccuracy : false,
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 5,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
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
;
$ionicPlatform.ready(function()
console.log("[IONIC PLATFORM IS NOW READY]");
//-- First launch a basic geolocalisation to get user acceptance of geosharing ;)
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS1] Location from Phonegap');
,
function (error)
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
//-- test adaptation depuis l'app jquery
var callbackFn = function(location)
console.log('[BackgroundGeoLocation] Update callback: ' + location.latitude + ',' + location.longitude);
;
var failureFn = function(error)
console.log('[BackgroundGeoLocation] Error: '+error);
;
$cordovaBackgroundGeolocation.configure(callbackFn, failureFn, options);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
$cordovaBackgroundGeolocation.start();
//-- Just a timeout to retreive long / lat
$timeout(function()
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS3] Location from Phonegap');
startPos = location;
$scope.$apply(function ()
$scope.lat_geo = startPos.coords.latitude;
$scope.long_geo = startPos.coords.longitude;
);
console.log("[GEOLOCAL BASIC] OK this time :)");
,
function (error)
console.log('[GEOLOCAL JS3] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
, 3000);
);
//-- End Geolocal
)
I've put all my code (a complete ionic app starter) on github: https://github.com/Jeff86/ionic_ngcordova_backgroundgeo_test/tree/master
ios angularjs geolocation ionic-framework ngcordova
Goal of the app: get geolocation on each move and log location either when app is in foreground and background.
I've tried so many code and combination but I can't manage to have it working (2 days from now...).
The classic geolocation (getCurrentPosition) is working fine but when we close the app the background geolocation is launched but nothing happen... Function "callbackFn" is never fired.
I'm testing on IOS with xcode > Capabilities Audio & location activated for background activity. I also made working the jQuery sample example given in plugin so I saw it working but never with ionic/angularjs.
Here is the current controller handling the background:
.controller('TestCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window)
$scope.lat_geo = "loading lat...";
$scope.long_geo = "loading long...";
//-- Geolocal launch
var options =
enableHighAccuracy : false,
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 5,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
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
;
$ionicPlatform.ready(function()
console.log("[IONIC PLATFORM IS NOW READY]");
//-- First launch a basic geolocalisation to get user acceptance of geosharing ;)
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS1] Location from Phonegap');
,
function (error)
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
//-- test adaptation depuis l'app jquery
var callbackFn = function(location)
console.log('[BackgroundGeoLocation] Update callback: ' + location.latitude + ',' + location.longitude);
;
var failureFn = function(error)
console.log('[BackgroundGeoLocation] Error: '+error);
;
$cordovaBackgroundGeolocation.configure(callbackFn, failureFn, options);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
$cordovaBackgroundGeolocation.start();
//-- Just a timeout to retreive long / lat
$timeout(function()
navigator.geolocation.getCurrentPosition(function(location)
console.log('[GEOLOCAL JS3] Location from Phonegap');
startPos = location;
$scope.$apply(function ()
$scope.lat_geo = startPos.coords.latitude;
$scope.long_geo = startPos.coords.longitude;
);
console.log("[GEOLOCAL BASIC] OK this time :)");
,
function (error)
console.log('[GEOLOCAL JS3] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
,options);
, 3000);
);
//-- End Geolocal
)
I've put all my code (a complete ionic app starter) on github: https://github.com/Jeff86/ionic_ngcordova_backgroundgeo_test/tree/master
ios angularjs geolocation ionic-framework ngcordova
ios angularjs geolocation ionic-framework ngcordova
asked Feb 22 '15 at 17:01
Jeff86
85311
85311
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I read this article http://ngcordova.com/docs/plugins/backgroundGeolocation/
I see that you should put your code into
document.addEventListener("deviceready", function () ... );
Do you find any solution?
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
add a comment |
up vote
0
down vote
You definitely don't want to use the std Cordova-geolocation plugin in the bg, it'll kill the battery in no time.
I'm the author of the underlying background-geolocation plugin for Ionic. I've created a New Ionic-based SampleApp.
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter inbehavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.
– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I read this article http://ngcordova.com/docs/plugins/backgroundGeolocation/
I see that you should put your code into
document.addEventListener("deviceready", function () ... );
Do you find any solution?
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
add a comment |
up vote
0
down vote
I read this article http://ngcordova.com/docs/plugins/backgroundGeolocation/
I see that you should put your code into
document.addEventListener("deviceready", function () ... );
Do you find any solution?
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
add a comment |
up vote
0
down vote
up vote
0
down vote
I read this article http://ngcordova.com/docs/plugins/backgroundGeolocation/
I see that you should put your code into
document.addEventListener("deviceready", function () ... );
Do you find any solution?
I read this article http://ngcordova.com/docs/plugins/backgroundGeolocation/
I see that you should put your code into
document.addEventListener("deviceready", function () ... );
Do you find any solution?
answered Apr 3 '15 at 2:15
phapsu
213
213
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
add a comment |
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
Hi, I did tried to encapsulate with deviceready but didn't made the trick. You can see on controller.js that I put it in comment on line 70. For now I just gave up to use this bglocation as I don't have time to spend on it, maybe in few months.
– Jeff86
Apr 8 '15 at 14:18
add a comment |
up vote
0
down vote
You definitely don't want to use the std Cordova-geolocation plugin in the bg, it'll kill the battery in no time.
I'm the author of the underlying background-geolocation plugin for Ionic. I've created a New Ionic-based SampleApp.
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter inbehavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.
– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
add a comment |
up vote
0
down vote
You definitely don't want to use the std Cordova-geolocation plugin in the bg, it'll kill the battery in no time.
I'm the author of the underlying background-geolocation plugin for Ionic. I've created a New Ionic-based SampleApp.
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter inbehavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.
– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
add a comment |
up vote
0
down vote
up vote
0
down vote
You definitely don't want to use the std Cordova-geolocation plugin in the bg, it'll kill the battery in no time.
I'm the author of the underlying background-geolocation plugin for Ionic. I've created a New Ionic-based SampleApp.
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp
You definitely don't want to use the std Cordova-geolocation plugin in the bg, it'll kill the battery in no time.
I'm the author of the underlying background-geolocation plugin for Ionic. I've created a New Ionic-based SampleApp.
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp
edited Sep 10 '15 at 19:21
answered Jun 6 '15 at 0:10
Christocracy
6817
6817
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter inbehavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.
– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
add a comment |
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter inbehavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.
– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
RTFM, that's clearly documented. That Android version is no longer supported, btw. It eats the battery like ants at a picnic. I don't recommend that for a production app, especially if you want your users to like you.
– Christocracy
Sep 10 '15 at 11:54
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter in
behavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.– Toskan
Sep 12 '15 at 22:21
yes, I found it. It would be kinda nice though, if you state the things that do not work at all for a platform, in the code sample. Instead of writing at lengths about it, and mentioning in the last chapter in
behavior
that something actually does not work at all. Anyway I need to check the location only every, say, 30 minutes.– Toskan
Sep 12 '15 at 22:21
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
The version you're using is no longer supported (and hasn't been for at least 6 months). The new repo is here github.com/transistorsoft/cordova-background-geolocation-lt
– Christocracy
Sep 13 '15 at 22:38
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
If you have further issues, you'll be better served raising issues directly at the repo.
– Christocracy
Sep 13 '15 at 22:39
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28660582%2fget-working-ionic-ngcordova-background-geolocation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown