I am able to get the events but only when app is running in foreground or in background state, but not receiving any notifications in killed state. May be it's due to Android 8/9 OS as I tested it only on Android 9 and don't have lower OS version devices.
var geofence = require("ti.android.geofence");
var locationAllowed = false;
function checkPermissions(cb){
if (Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
locationAllowed = true;
(cb != undefined) && cb();
} else {
Ti.API.warn('Location permissions not granted! Asking now...');
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
locationAllowed = e.success;
(cb != undefined) && cb();
});
}
}
function addFences(){
geofence.addGeofences({
clearExistingFences : false,
fences : [
{
"id" : "office",
"latitude" : 28.41259,
"longitude" : 77.0425996,
"radius" : 500,
"transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
'dwellTime' : 5 * 60 * 1000,
//Notification
"title" : "Office Address",
'message' : 'I am at office address now.',
"accentColor" : "#00AEE6",
'smallIcon' : 'push',
"type" : geofence.TYPE_PLACE_FENCE,
"showGooglePlaceBigImage" : true
},
{
"id" : "huda_metro",
"latitude" : 28.4615863,
"longitude" : 77.062657,
"radius" : 500,
"transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
'dwellTime' : 5 * 60 * 1000,
//Notification
"title" : "Huda City Centre",
'message' : 'I am at Huda City Centre now.',
"accentColor" : "#2AC635",
'smallIcon' : 'push',
"type" : geofence.TYPE_PLACE_FENCE,
"showGooglePlaceBigImage" : true
},
{
"id" : "home",
"latitude" : 28.4947681,
"longitude" : 77.158355,
"radius" : 500,
"transitions" : [ geofence.GEOFENCE_TRANSITION_ENTER, geofence.GEOFENCE_TRANSITION_DWELL, geofence.GEOFENCE_TRANSITION_EXIT ],
'dwellTime' : 5 * 60 * 1000,
//Notification
"title" : "My Home",
'message' : 'I am at HOME now.',
"accentColor" : "#D52C7D",
'smallIcon' : 'push',
"type" : geofence.TYPE_PLACE_FENCE,
"showGooglePlaceBigImage" : true
}
]
});
startFencing();
}
function startFencing(){
if (locationAllowed) {
geofence.startMonitoring();
}
}
function stopAllFencing(){
geofence.clearExistingFences();
}
function stopMonitoring(){
geofence.stopMonitoring();
}
geofence.addEventListener(geofence.ERROR, function(e){
Ti.API.error("GEOFENCE ERROR");
Ti.API.error(e.message);
});
geofence.addEventListener(geofence.ENTERED, function(e){
alert("ENTERED");
alert(JSON.stringify(e));
});
geofence.addEventListener(geofence.EXITED, function(e){
alert("EXITED");
alert(JSON.stringify(e));
});
geofence.addEventListener(geofence.DWELL, function(e){
alert("DWELL");
alert(JSON.stringify(e));
});
geofence.addEventListener(geofence.STARTED_MONITORING, function(e){
alert("STARTED_MONITORING");
alert("Monitoring...");
});
geofence.addEventListener(geofence.STOPPED_MONITORING, function(e){
alert("STOPPED_MONITORING");
alert("RIP!");
});
geofence.addEventListener(geofence.GEOFENCES_ADDED, function(e){
alert("GEOFENCES_ADDED");
alert("Ready to start monitoring!");
});
geofence.addEventListener(geofence.NOTIFICATION_CLICKED, function(e){
alert("NOTIFICATION_CLICKED");
alert(JSON.stringify(e));
});
checkPermissions(addFences);
I am testing the app nearby to physical location of first fence and whenever I spoof any other location to check exit or dwell events for any fence, I am not getting any events triggered up.
The only event triggered is ENTER and this is also fired only for the first location even if my current location is nearby to third geofence item.
I am spoofing the locations and getting correct co-ordinates for location updates in the Ti.Geolocation's location
event.