I use the plugin cordova-mauron85-background-geolocation
I use ionic-native Background-Geolocation
to check whether background tracking is works, I send notification.
but with below code, but dosent’ work …what wrong with code ?
at constructor, I call startLocation function to start track of background geolocation
constructor(public ...){
this.startTracking();
}
startTracking(){
let config = {
desiredAccuracy: 0,
stationaryRadius: 20,
distanceFilter: 10,
debug: true,
interval: 2000
};
this.backgroundGeolocation.configure(config).subscribe((location) => {
console.log('BackgroundGeolocation: ' + location.latitude + ',' + location.longitude);
var data={
"app_id": "xxxxx",
"include_player_ids": ["xxx"],
"data": {"foo": "bar"},
"contents": {"en": "2323"+location}
}
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
if(this.platform.is('android')){
this.http.post('https://onesignal.com/api/v1/notifications', data, options).toPromise().then((res)=>{
console.log(res.json())
}).catch((error)=>{
alert(error);
})
}else{
}
}, (err) => {
console.log(err);
});
// Turn ON the background-geolocation system.
this.backgroundGeolocation.start();
// Foreground Tracking
let options = {
frequency: 3000,
enableHighAccuracy: true
};
this.watch = this.geo.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position) => {
console.log(position);
});
}