GPS position when mobile app is in background (with ionicframework)

后端 未结 2 1324
萌比男神i
萌比男神i 2021-02-06 12:26

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

相关标签:
2条回答
  • 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();
    
    });
    
    0 讨论(0)
  • 2021-02-06 13:19

    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.

    0 讨论(0)
提交回复
热议问题