Ionic Geolocation with Background Location

Ionic Geolocation with Background Location

Ionic Geolocation with Background Location Service




Member since 2015


5 years ago
1 year ago


I am trying to find a fix for android. If you purchased this and need a refund send me an email. apologies.

Similar to Ionic Geolocation but with Background Location Updates enabled.

A barebone ionic geolocation application for iOS and Android that reads your phone gps location and displays it. It's all you need to get started on your location based application. I know you can figure it out on your own, but this will save you time, especially when you get stuck :)

I am updating the location and speed every second, you can change this to what you need. I haven't had any luck with using cordova watchPosition so I am doing my own polling here. Speed is displayed in Meters per second. You can now check if Location Service is disabled for your app.

After you install ionic you have to install cordova geolocation plugin.

Check out my other useful starters are here: Great Ionic Starters.


  • All of the geolocation logic is contained in 'Geolocation' service in services.js
  • Two things you can modify in services are the handling of errors and geolocation options

    ``` var options = { enableHighAccuracy: true, // USE HIGH ACCURACY timeout: 15000, // HOW LONG TO WAIT FOR A RESPONSE maximumAge: 0 // SET TO ZERO SO NEW VALUES ARE ALWAYS RETURNED };

    function showError(error) { console.log('Unable to get the location.'); // LOG ERRORS } ```

  • DashCtrl controller in controllers.js is used to display the values from geolocation service
  • Data is displayed in tab-dash.html
  • Changes to the values are wrapped in $scope.$apply(function () { } to enable data binding
  • Geolocation data is obtained by calling Geolocation.checkLocation(callback), this function takes a function as parameter to return the value
  • You can change the 1000 (1 second) interval polling on this line:
  • setInterval( function(){ Geolocation.checkLocation( $scope.callback ); }, 1000);
  • Call Geolocation.isGPSEnabled() to see if Location Service is enabled
  • Geolocation.getPosition() returns a result array
  • return new Array(latitude, longitude, altitude, speed, GPSEnabled); where you can check the last element to see if GPS is enabled.


Install Ionic

Open zipped folder in terminal

  • go to the project folder
  • Install Ionic sudo npm install -g ionic
  • ionic platform add ios
  • ionic platform add android
  • cordova plugin add cordova-plugin-geolocation
  • cordova plugin add cordova-plugin-mauron85-background-geolocation
  • ionic emulate ios
  • ionic run android (use run if you use genymotion)
  • the app will ask you to share your location
  • If you are using an emulator you will have to trigger the location manually

Common Issues

  • There are some reported issues with nexus phones and speed variable. Try setting enableHighAccuracy to false in the options array. If this doesn't work then there is an incompatibility with cordova geolocation and the new android sdk. I am still trying to resolve this.
  • Notification text is set to 'disabled' on android. In the code remove this line from the configuration.

Payment Information

  • The payment on this site is processed by and sometimes your bank will decline the charges if they don't recognize it. You can contact your bank or try a different card.


  • Leave a comment if you get stuck on anything
  • If you email me directly it might get caught in the spam filter
  • And Kudos if you leave a Rating! =)

Stay in Touch

Icon made by [Freepik]( "Freepik") from []( "Flaticon") is licensed under [CC BY 3.0]( "Creative Commons BY 3.0")