ios


Get working Ionic + ngCordova + background geolocation


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
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?
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

Related Links

Gradually change background color based on scroll
UICollectionViewCell pushed down when embedded in navigation controller
self.navigationController always returns nil using storyboard to storyboard navigation
How to do unwind segue in Xcode
Camera view overlay with ROI
App size with an extension in App Store
Setting UITextView's cursor position generates warning
PKRevealController Crashes
Symbols '$£¥ €' missing from font after ios system upgrade from 9 - 10
Different Text Attributes per Link in UITextView/UILabel Swift
cache array of objects iOS
Is the network performance of WKWebView slower than native safari?
Facebook SDK error for subscript members [duplicate]
After upgrading to unity 5.4 Substance crash after building for iOS and goes missing
iOS 10 Firebase Notification not showing on background
Handle push notification while in phone call ios

Categories

HOME
odoo-10
vb.net
graylog2
cql3
svg.js
cross-domain
py.test
eps
silverlight
copy-paste
asciidoc
obiee
graphengine
deserialization
message
oracle11gr2
libpcap
stm32f4discovery
jpos
realm-java
opencms
nice-language
cadvisor
digital-logic
smallbasic
desire2learn
codewarrior
expression-trees
feedly
rdf4j
instance
localdb
machine-language
groove
hamcrest
google-domain-api
paypal-rest-sdk
macvim
jsonstore
rft
h5py
pulseaudio
name-mangling
cabal-install
measurement-protocol
coldfusion-11
webtrends
intrinsics
flotr2
viewengine
strace
post-processor
gem
google-swiffy
android-print-framework
access-log
fortrabbit
javaw
lossless-compression
nolio
tab-delimited
razor-2
sqlhelper
android-menu
django-supervisor
requiredfieldvalidator
sonata-media-bundle
delphi-2009
tlb
emitmapper
xcache
nsimageview
sugar.js
pubdate
visual-assist
hogan.js
cloud-hosting
libavg
documentviewer
onmouseout
nsinvocation
magento-1.5
data-oriented-design
emacs-ecb
xmltextwriter
ryz
cracker
development-machine
versant-vod
usenet

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App