How to background service using Angular


I try to make a simple app witch send current Location to the server (POST).
for the moment I can view the position and also send it to the server, but how to make my app running event in the background ?

    currentGeoLocation: any;

    enableLocationServices(): void {
        geoLocation.isEnabled().then(enabled => {
            if (!enabled) {
                geoLocation.enableLocationRequest().then(() => this.showLocation());
            } else {

    private showLocation(): void {
        geoLocation.watchLocation(location => {
            this.currentGeoLocation = location;
            console.log("lat : " + this.currentGeoLocation.latitude);
            console.log("lon : " + this.currentGeoLocation.longitude);
            console.log("alt : " + this.currentGeoLocation.altitude);
            console.log("speed : " + this.currentGeoLocation.speed);
            console.log("timestamp : " + this.currentGeoLocation.timestamp);

        }, error => {
        }, {
                desiredAccuracy: 3,
                updateDistance: 10,
                minimumUpdateTime: 1000 * 9


Create a background service where you can watch for location and keep posting same to your server.

Examples for background services:


sadly, the android example app does not work… there’s an issue opened there and no replies :frowning:


Which issue? I have been using it in my Angular apps, it works.


strange issue, to be honest. do not understand why it happens (and even if i replace the cinstant w/ its value, found in android developer’s manual, it still crashes on the next line, like if it cant see native methods/classes)


I have commented on the issue, that particular code needs Android 7.x.


thanks! i was pretty sure this code is somehow necessary for the whole thing to be working, but now, looking more closely on the code, i see that it’s just setting up a local notification, and all the background thread business is above the line where it was crashing

maybe this question is not purely related to the original one, however i’m still missing how is it possible to communicate with the main thread of the app from the bg one. how can i pass my data from this job and/or trigger an event? thank you for you help
ps: im not actually using angular, just found this thread on the forum. would it be better to create one? not sure! :slight_smile:


In Android you can use Intents / Broadcast Events. For iOS you may use NSNotificationCenter.