Get location while app is in background or screen is locked

I want to build a basic location tracker, like Strava, but with very few features. The app should be able to get my current accurate location say each 5 seconds, even when the app is in background or the screen is locked. Is there a Ionic 5+ / Capacitor V2+ solution for this?
I know there is the @mauron85/cordova-plugin-background-geolocation package, but it’s based on Cordova and no longer maintained. Is there an up to date solution for this, or is switching to Java my only option?

1 Like

Thanks Hanks,
meanwhile I also found this. I tested it briefly last night and it appeared to work.
Now I’m trying to get the plugin working in a fresh project, but no way I can make the plugin available in the android project. Not sure what sequence of commands I typed last night, but now I’ve been trying for some hours and no result. Drives me crazy.

That linked capacitor community background geolocation plugin works flawlessly on my Android and iOS Ionic app. It even allows background XHR/fetch requests to fire in the background. Have had no issues with it after a few weeks of testing.
Make sure you add these required code in Android studio after the ionic build.

You might consider Flutter for this type of apps