# Location is not being sent when app is closed. Can anyone point out what i am missing?

**URL:** <https://forum.ionicframework.com/t/location-is-not-being-sent-when-app-is-closed-can-anyone-point-out-what-i-am-missing/97124>\
**Category:** Ionic Native\
**Created:** [July 6, 2017, 7:40am UTC](https://forum.ionicframework.com/t/location-is-not-being-sent-when-app-is-closed-can-anyone-point-out-what-i-am-missing/97124 "2017-07-06T07:40:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnaresh](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@mnaresh](https://forum.ionicframework.com/u/mnaresh)\
**Post date:** [July 6, 2017, 7:40am UTC](https://forum.ionicframework.com/t/location-is-not-being-sent-when-app-is-closed-can-anyone-point-out-what-i-am-missing/97124/1 "2017-07-06T07:40:21Z")

</div>

I am working on an Ionic app. I am trying to send location in background every 1 hour. I am using official Background Geolocation plugin. Location is being sent when the app is open either in foreground or background but as soon as i close the app my location is not being sent to database. Although my debug mode is active and i can see toast message and beep sound even after closing app. Can anyone point out where i am making mistake? Here is my code.

{  
platform.ready().then(() =\> {  
this.getLocation();  
this.backgroundGeolocation.start();  
});  
}

```
getLocation() {
const config: BackgroundGeolocationConfig = {
  locationProvider: this.backgroundGeolocation.LocationProvider.ANDROID_DISTANCE_FILTER_PROVIDER,
  desiredAccuracy: 10,
  stationaryRadius: 5,
  startOnBoot: true,
  notificationIconColor: '#4CAF50',
  interval: 5000,
  fastestInterval: 5000,
  activitiesInterval: 5000,
  distanceFilter: 5,

  debug: true, // enable this hear sounds for background-geolocation life-cycle.
  stopOnTerminate: false, // enable this to clear background location settings when the app terminates
  stopOnStillActivity: false
};

this.backgroundGeolocation.configure(config).subscribe((location) => {
  this.loc.push(location);
  this.storage.save('Location', this.loc).subscribe();
  console.log('Location :', location);
  this.sendLocation(location);
});

```

}

```
sendLocation(data) {
const url = 'my-url';
const payload = {
  date_added: moment(data.time).format('DD/MM/YYYY'),
  identity: '',
  ipaddress: '',
  latitude: data.latitude,
  longitude: data.longitude,
  mobile: 'phoneNo',
  network_name: '',
  status: '',
  time_added: moment(data.time).format('hh:mm A'),
}
this.http.post(url, payload).map(res => res.json()).subscribe(data => console.log('location inserted: ', data))

```

}

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [July 8, 2017, 12:00am UTC](https://forum.ionicframework.com/t/location-is-not-being-sent-when-app-is-closed-can-anyone-point-out-what-i-am-missing/97124/2 "2017-07-08T00:00:02Z")

</div>

Please edit your post, it is not very readable at the moment.  
Use the `</>` button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ````` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

---

<div class="post-metadata">

**Author:** ![JayKay](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@JayKay](https://forum.ionicframework.com/u/JayKay)\
**Post date:** [July 8, 2017, 9:20am UTC](https://forum.ionicframework.com/t/location-is-not-being-sent-when-app-is-closed-can-anyone-point-out-what-i-am-missing/97124/3 "2017-07-08T09:20:20Z")

</div>

The Background Geolocation Plugin only works when your is running in foreground or background. It doesn’t work when the app is closed.

Sending the user’s Geolocation every x minutes (even when the app is closed) won’t work.  
You could take a look at geofences, maybe that already helps to meet your requirements. Geofences will be checked even when the app is closed.
