5

I need to realize an app that store user journey (path) when he moves from A to B. Now, I know that ionicframework can use GPS, but what happen when my APP go to background ? How can my app continue to store user position ? Is this possible ? Are there plugins (not $600+ please) that I can use ?

ZioBudda
  • 948
  • 2
  • 12
  • 24
  • Duplicate of http://stackoverflow.com/questions/32386231/navigator-geolocation-getcurrentposition-when-screen-is-locked – Jess Patton Sep 04 '15 at 15:10
  • Nope, this is not a duplicate, that other answer is referencing a premium plugin @ZioBudda was mentioning – Gajotres Sep 04 '15 at 16:12

2 Answers2

9

I just finished writing a new cordova background geolocation plugin for ios and android, its free and simple! try it out:

https://github.com/pmwisdom/cordova-background-geolocation-services

Ionic Usage :

//Wait for cordova / ionic ready to use the plugin
ionic.Platform.ready(function(){
    //Make sure to get at least one GPS coordinate in the foreground before starting background services
    navigator.geolocation.getCurrentPosition();

    //1. Get plugin
    var bgLocationServices =  window.plugins.backgroundLocationServices;

    //2. Configure Plugin
    bgLocationServices.configure({
         desiredAccuracy: 20, 
         distanceFilter: 5, 
         notificationTitle: 'BG Plugin', 
         notificationText: 'Tracking',
         debug: true, 
         interval: 9000, 
         fastestInterval: 5000
    });

    //3. Register a callback for location updates, this is where location objects will be sent in the background
    bgLocationServices.registerForLocationUpdates(function(location) {
         console.log("We got a BG Update" + JSON.stringify(location));
    }, function(err) {
         console.log("Error: Didn't get an update", err);
    });

    //4. Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
    bgLocationServices.start();


    ///later, to stop
    bgLocationServices.stop();

});
Mirrorcell
  • 384
  • 2
  • 10
  • Please include some sample usage here. – Teepeemm Nov 06 '15 at 18:29
  • What kind of sample usage would you like? The github repo shows usage details. – Mirrorcell Nov 06 '15 at 23:33
  • @Mirrorcell: Great Plugin...works like Charm.. :) But my real concern is when user remove/kill app from list of last visted app(by pressing right most squre icon over android phone..It shows all listed) . It doesn't work. It suppose to work..like Whatsapp or GMap...Please correct me. Thanks – Niks Jain Jun 24 '16 at 14:44
  • 2
    Hi @Niks, tracking does not work after the application has been force closed. How do WhatsApp and Google maps work in this way? If I force close Google Maps, for instance, the tracking stops on my phone. – Mirrorcell Jun 28 '16 at 15:25
3

It's possible with a plugin you're referring as a $600+ premium plugin.

People usually forget that older versions are also available, including last viable Android/iOS version: https://github.com/christocracy/cordova-plugin-background-geolocation/tree/0.3.7

ionic plugin add cordova-plugin-background-geolocation@1.0.5

Currently, other distinct versions do not exist, everything else is just a fork of this original plugin.

Gajotres
  • 57,309
  • 16
  • 102
  • 130
  • I'm trying to use your provided plugin for Background geolocation. But I'm getting notification flash as "Background Geolocation: INVALID LICENSE". Could you please help me out to fix it? Let me know if you need more info about my script. Thanks in-advance. – Niks Jain Jun 24 '16 at 14:05