pavan2
April 26, 2018, 7:23am
1
Hi Ionites,
I am currently using this plugin with Ionic 3. I got the geofences working,and they seem to work when enter/leave geofence locations. The only problem is that the notification is not working. In the onTransitionReceived() I throw a toast, which is shown when entering the location/adding a fence. Also I hear a sound of a notification coming in, yet I do not see a notification…
can you share the code for adding geofences and ontransition received method codes??
pavan2
April 26, 2018, 10:22am
3
Sure
This is the code for adding the Geofences. I am getting the list of data from the API.
getGeofencedata() {
this.getFenceData().subscribe(geofenceObj => {
this._geoFenceList = geofenceObj.data;
if (this._geoFenceList.length > 0) {
let fenceList = this.getFenceList(this._geoFenceList);
this.addorUpdateFence(JSON.parse(fenceList));
}
}, err => {
console.log('geofence not set');
});
}
getFenceList(rawfencelist) {
return JSON.stringify(rawfencelist.filter(f => f).map(fence => {
return fence = {
id: fence._id,
latitude: parseFloat(fence.geocoordinates.x),
longitude: parseFloat(fence.geocoordinates.y),
radius: parseFloat(fence.radiusinmeters),
transitionType: 1,
notification: {
title: fence.notificationtitle,
text: fence.notificationmessage,
openAppOnClick: true
}
}
}));
}
This is my onTransitionReceived() method code.
this.geofence.onTransitionReceived().subscribe(resp => {
console.log("geofence on transition recieved", resp);
alert(JSON.stringify(resp));
});
Try with different devices than check whether it’s able to show notification or not?