description
"enterregions" event does not work for Geofence module.
-
http://docs.appcelerator.com/platform/latest/#!/api/Modules.Geofence
Just include the module to the project then run the following code to the device
-
https://platform.appcelerator.com/#/download
Test code
var window = Titanium.UI.createWindow({
backgroundColor : 'red'
});
var titleInWinA = Ti.UI.createLabel({
text : 'Location',
left : 70,
top : 100,
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
});
window.add(titleInWinA);
var lat;
var lon;
if (Ti.Geolocation.locationServicesEnabled) {
Titanium.Geolocation.purpose = 'Get Current Location';
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
alert('Error: ' + e.error);
} else {
Ti.API.info(e.coords.latitude + '\n' + e.coords.longitude);
titleInWinA.setText(e.coords.latitude + '\n' + e.coords.longitude);
lat = e.coords.latitude;
lon = e.coords.longitude;
Enterregions();
}
});
} else {
alert('Please enable location services');
}
function Enterregions() {
var Geofence = require("ti.geofence");
var newRegion = Geofence.createRegion({
center : {
latitude : lat,
longitude : lon
},
radius : 500,
identifier : 'Appcelerator'
});
Geofence.startMonitoringForRegions([newRegion]);
Geofence.addEventListener("enterregions", function(e) {
Ti.API.log('####### enterregion #######: ' + JSON.stringify(e));
alert('enter region fired');
});
Geofence.addEventListener("monitorregions", function(e) {
Ti.API.log('####### monitorregions #######: ' + JSON.stringify(e));
});
}
window.open();
<key>NSLocationAlwaysUsageDescription</key>
<string>Specify the reason for accessing the user's location information.
This appears in the alert dialog when asking the user for permission to
access their location.</string>
Thanks
Before I start further investigations, please validate the issue with this (corrected) demo-code, yours does not look valid for newer iOS-versions:
Most important: - Validate the permissions status - Don't store global variables for this - Don't require a module inside an event-listener - Use Ti.API.info instead of Ti.API.log ("log" might not be displayed in the default log-level) Also ensure to test on a device, thanks!
Putting into next sprint for further investigation.
Closing as invalid. If incorrect, please reopen.