Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230107

Background geolocation not working

$
0
0

Try this:

import {
    BackgroundGeolocation ,
    BackgroundGeolocationConfig ,
    BackgroundGeolocationResponse ,
    BackgroundGeolocationLocationProvider,
    BackgroundGeolocationEvents
} from '@ionic-native/background-geolocation';

...

let config: BackgroundGeolocationConfig = {
    desiredAccuracy: 10,
    stationaryRadius: 1,
    distanceFilter: 1, 
    debug: true,
    interval: 2000,
    stopOnTerminate: false,
    url: 'my-link', // location is sent automatically to this url in background or foreground or app is closed
    postTemplate: {
        lat: '@latitude',
        lng: '@longitude'
};
	
this.backgroundGeolocation.configure(config).then((location: BackgroundGeolocationResponse)=>{
    this.globals.lat = location.latitude;
    this.globals.lng = location.longitude;
}, (error) => {
    alert(error);
});

this.backgroundGeolocation.on(BackgroundGeolocationEvents['location']).subscribe((location) => { 
    // here put code for the action you want after location changed event
    // this code does not work when app is closed
});

This works in foreground and background!


Viewing all articles
Browse latest Browse all 230107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>