Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2869] Calling removeEventListener on Geolocation event prevents addEventListener from working

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2013-03-08T22:42:00.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelseventlistener, geolocation
ReporterMartyn Joyce
AssigneeDaniel Sefton
Created2012-05-30T04:45:46.000+0000
Updated2016-03-08T07:47:49.000+0000

Description

If Ti.Geolocation.removeEventListener() is called when Ti.Geolocation.addEventListener() has NOT been added the system remembers and subsequently removes the listener once you add it, even if this is at a later time. In the following example use these click orders: This works Correctly: - Add Event Listener - Remove Event Listener - Add Event listener This does not work correctly - Remove Event Listener - Add Event Listener however clicking Add event Listener again will work. This also stacks. Clicking Remove Event Listener 5 times, means that Add Event Listener needs to be clicked 5 times before it starts delivering events. The example shows calls for 'heading' but I believe this also occurs for location.

Ti.Geolocation.preferredProvider 				=  	Ti.Geolocation.PROVIDER_GPS;
Ti.Geolocation.accuracy 					= 	Titanium.Geolocation.ACCURACY_HIGH;
Ti.Geolocation.purpose 						= 	'Determine Position';
Ti.Geolocation.headingFilter 					= 	5;
Ti.Geolocation.showCalibration 					= 	true;
Ti.Geolocation.distanceFilter					=	10;

	
var win1 = Titanium.UI.createWindow({  
    backgroundColor:'#fff'
});

var btnAdd = Ti.UI.createButton({
	top: 100,
	title: 'Add Event Listener',
})

btnAdd.addEventListener('click', addGeoEvent);

var btnRemove = Ti.UI.createButton({
	top:	200,
	title: 'Remove Event Listener',
})

btnRemove.addEventListener('click', removeGeoEvent);

win1.add(btnAdd);
win1.add(btnRemove);

function addGeoEvent(){
	Ti.API.info('adding listener');
	Ti.Geolocation.addEventListener('heading', headingCallback);
}

function removeGeoEvent(){
	Ti.API.info('removing listener');
	Ti.Geolocation.removeEventListener('heading', headingCallback);
}

function headingCallback(e){
	
	Ti.API.info('heading = ' + e.heading.magneticHeading);
	
}

win1.open();



Comments

  1. Nikhil Sharma 2012-06-07

    Hi Martyn, What platform you're referring to Android or iOS? I tested the above test case on iPhone and its working fine.
  2. Martyn Joyce 2012-06-12

    Hi Nikhil, this is on iOS version 5.1 however, apologies, my use-case above seems to be slightly off: This DOES work in the first instance 1 - Remove Event Listener 2 - Add Event Listener But if you continue it stops working i.e. 1 - Remove Event Listener 2 - Add Event Listener 3 - Remove Event Listener 4 - Remove Event Listener 5 - Remove Event Listener 6 - Add Event Listener - no events are generated here 7 - Add Event Listener - no events are generated here 8 - Add Event Listener - events are now generated In practice this occurs because we 'remove' as a safety measure to make sure the gps is turned off, however using variables to keep track of the status has solved my problem temporarily. thanks
  3. Shak Hossain 2013-03-08

    Hi, With a test the the latest TISDK 3.0.2 or CI, this issue was not reproducible. Can you please test our latest SDK? If the problem exists, you can provide us some log files. Thanks,

JSON Source