How to use Background geolocalisation?


I am trying to add this plugin:

So I am following the docs from ionic:

But it is not working at all.

Simply my code is:

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {BackgroundGeolocation} from 'ionic-native';
import {Observable} from 'rxjs/Observable';
import {Platform} from 'ionic-angular';

  templateUrl: 'build/pages/about/about.html'
export class AboutPage {
  public AboutPage:string;

  constructor(platform: Platform) {
      this.platform = platform;

platform.ready().then(() => {

    // BackgroundGeolocation is highly configurable. See platform specific configuration options
    let config = {
            desiredAccuracy: 10,
            stationaryRadius: 20,
            distanceFilter: 30,
            debug: true, //  enable this hear sounds for background-geolocation life-cycle.
            stopOnTerminate: false, // enable this to clear background location settings when the app terminates

       .then((location) => {
            console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);

            // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
            // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
            // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
            BackgroundGeolocation.finish(); // FOR IOS ONLY
       .catch((error) => {
            console.log('BackgroundGeolocation error');

    // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.

// If you wish to turn OFF background-tracking, call the #stop method.


try this tutorial? also make sure to test in the emulator, it wont work in the browser.

1 Like

Thanks. I am trying.

let me know how it goes, i didnt try it myself yet. but i will be implementing it soon. maybe you can share the code once you tested.

1 Like

did it work for you?

This tutorial is working, when app is in foreground.
If app is background state its not working…

Please suggest me if i did any mistake.

Thank you…!

If you want to debug with location in your browser you can with Visual Studio Code. They have a cordova debug tool which is very handy.

Very easy to use (on mac at least)

Hi Sulot,

Thanks for the reply…!

I want to send user location to server(Web server), if app is in background or foreground.

Please help me, how to achieve this.