Currently trying to build a location based triggered local notification in ionic 4 - I started by using native background mode (implemented in the initialize App of app.ts) which is working and tracking user location with the watchPosition(). However I'm finding it hard to get the trigger of the local notification to work. My code that I have tried is attached, ant help would be much appreciated!
this.backgroundMode.on('activate').subscribe(() => {
console.log('activated');
const watchLocation = this.geolocation.watchPosition();
watchLocation.subscribe((data) => {
data.coords.latitude;
data.coords.longitude;
console.log('current Position', data.coords.latitude, data.coords.longitude);
this.locationNotification();
});
});
this.backgroundMode.enable();
}
locationNotification() {
this.localNotifcation.schedule({
id: 3,
title: 'Welcome to the show grounds!',
text: 'Click me to declare your entries!!',
sound: '',
trigger: {
type: 'location',
center: [53.3385394, -6.266703],
radius: 1000,
notifyOnEntry: true,
notifyOnExit: false,
single: true
},
vibrate: true,
foreground: true
});
}