Background Geolocation With Apache Cordova

Background geolocation looks like a simple thing to implement, but now with hybrid app, such as Apache Cordova apps. This is because all JavaScript code execution in WebView will be stopped when you’ll “minimize” app or your device will go to sleep mode. But this can be solved by using the native apps or Cordova plugins. Today we’ll learn how to create a mobile app with background geolocation feature using Apache Cordova and one plugin.

  • Install background geolocation plugin:

Simple use this plugin:

For Ionic framework / AngularJS apps I’m strongly recommend you to use this as an Angular service, like this:

Plugin GitHub/Download

18 thoughts on “Background Geolocation With Apache Cordova”

  1. Hello !

    Thank you for this article. However, I encounter an issue with the Service solution : backgroundGeoLocation is undefined.

    How do you access the plugin from a controller of your app ?

    Thank you!


    1. Hi,

      You can access it if you’ll inject it as dependency, like

      app.controller(‘myctrl’, [‘BackgroundGeolocationService’], ….

  2. I am using your Ionic way. But I am getting an error Uncaught “ReferenceError: backgroundGeoLocation is not defined”. Is there something else to do?

    1. I’m not sure this is in my scope of competence. The problem can be somewhere inside the plugin or it also can be inside the whatsapp. I can only suggest to somehow convert gif to jpg/png (for example using canvas or backend – I don’t know what is the best choice for you).

      1. Sorry I didn’t get you. I was enquiring about the blog you wrote about “Background Geolocation With Apache Cordova”. Sorry if my question was not clear.

  3. Pingback: Background geolocation in Ionic app | Develop and Conquer
  4. Thanks, Man. this is really helpful. you explained it much much better than official doc.
    keep it up. Thanks again.

  5. Bro..Will it work while app is closed? I think it is working only when the app gets “minimized“.

Leave a Reply

Your email address will not be published. Required fields are marked *