Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2294] iOS Geofence module: EnterRegions event does not fire.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2016-09-29T19:35:47.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sn/a
ComponentsGeofence
LabelsGeofence, module
ReporterMotiur Rahman
AssigneeHans Knöchel
Created2016-09-07T18:01:56.000+0000
Updated2018-08-06T17:37:00.000+0000

Description

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

Comments

  1. Hans Knöchel 2016-09-07

    Before I start further investigations, please validate the issue with this (corrected) demo-code, yours does not look valid for newer iOS-versions:
       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();
       
    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!
  2. Hans Knöchel 2016-09-13

    Putting into next sprint for further investigation.
  3. Eric Merriman 2018-08-06

    Closing as invalid. If incorrect, please reopen.

JSON Source