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!var Geofence = require("ti.geofence"); var window = Ti.UI.createWindow({ backgroundColor: 'white' }); var titleInWinA = Ti.UI.createLabel({ text: 'Receiving location ... ', left: 70, top: 100, }); window.add(titleInWinA); window.addEventListener("open", function() { checkLocationPermissions(); }); function checkLocationPermissions() { if (!Ti.Geolocation.hasLocationPermissions()) { Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) { if (!e.success) { Ti.API.error("Error requesting location permissions: " + e.error); return; } getCurrentPosition(); }); } else { getCurrentPosition(); } } function getCurrentPosition() { Ti.Geolocation.getCurrentPosition(function(e) { if (e.error) { alert('Error: ' + e.error); } else { Enterregions(e.coords.latitude, e.coords.longitude); } }); } function Enterregions(latitude, longitude) { Ti.API.info(latitude + '\n' + longitude); titleInWinA.setText(latitude + '\n' + longitude); var newRegion = Geofence.createRegion({ center: { latitude: latitude, longitude: longitude }, radius: 500, identifier: 'Appcelerator' }); Geofence.startMonitoringForRegions([newRegion]); Geofence.addEventListener("enterregions", function(e) { Ti.API.info('####### enterregion #######: ' + JSON.stringify(e)); alert('enter region fired'); }); Geofence.addEventListener("monitorregions", function(e) { Ti.API.info('####### monitorregions #######: ' + JSON.stringify(e)); }); } window.open();Putting into next sprint for further investigation.
Closing as invalid. If incorrect, please reopen.