# Get location while app is in background or screen is locked

**URL:** <https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732>\
**Category:** Capacitor\
**Created:** [April 26, 2021, 9:12pm UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732 "2021-04-26T21:12:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpper](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cpper](https://forum.ionicframework.com/u/cpper)\
**Post date:** [April 26, 2021, 9:12pm UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/1 "2021-04-26T21:12:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [April 27, 2021, 6:27am UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/2 "2021-04-27T06:27:45Z")

</div>

> [@Background Geolocation not work on background mode](https://forum.ionicframework.com/t/background-geolocation-not-work-on-background-mode/203844/2):
>
> Background Geolocation is a heavy task. There is only one Plugin i knew which works, is maintained and offers a good Support. Note: It does cost on android, but it’s not very expensive. In our team we decided to buy it

---

<div class="post-metadata">

**Author:** ![cpper](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cpper](https://forum.ionicframework.com/u/cpper)\
**Post date:** [April 27, 2021, 5:07pm UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/3 "2021-04-27T17:07:40Z")

</div>

Thanks Hanks,  
meanwhile I also found [this](https://github.com/capacitor-community/background-geolocation). 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.

---

<div class="post-metadata">

**Author:** ![Mikemas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mikemas](https://forum.ionicframework.com/u/Mikemas)\
**Post date:** [April 29, 2021, 1:02am UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/4 "2021-04-29T01:02:58Z")

</div>

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.

> **[capacitor-community/background-geolocation - Android](https://github.com/capacitor-community/background-geolocation/tree/0.3.x#android)**
>
> 0.3.x

---

<div class="post-metadata">

**Author:** ![mirko77](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirko77/32/137216_2.png) [@mirko77](https://forum.ionicframework.com/u/mirko77)\
**Post date:** [April 30, 2021, 3:03pm UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/5 "2021-04-30T15:03:52Z")

</div>

You might consider Flutter for this type of apps

---

<div class="post-metadata">

**Author:** ![dcarmona808](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@dcarmona808](https://forum.ionicframework.com/u/dcarmona808)\
**Post date:** [December 2, 2021, 2:56am UTC](https://forum.ionicframework.com/t/get-location-while-app-is-in-background-or-screen-is-locked/208732/6 "2021-12-02T02:56:00Z")

</div>

I currently use capacitor v3 I read the documentation of this same plugin for capacitor v3, I start the application but nothing happens when the app is in the background there will be something missing to configure or register the plugin in the mainactivity, could you help me
