Skip to content

Remove GeoLocation Event Listener #13554

Answered by ewanharris
beppo-ivel asked this question in Q&A
Discussion options

You must be logged in to vote

@beppo-ivel In order to remove an event listener you need to use a function declaration not an anonymous function, so for example the below JS should work

let Util = require('/util');
function doClick(e) {
	Ti.Geolocation.removeEventListener('location', locationListener);
	alert($.label.text);
}

function locationListener() {
	Util.record(e)
}

if (OS_ANDROID) {
	$.index.addEventListener('open', function() {
		if (!Ti.Geolocation.hasLocationPermissions()) {
	
		} else {
			Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;
			Ti.Geolocation.addEventListener('location', locationListener);
		}
	});
}
$.index.open();

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@beppo-ivel
Comment options

@ewanharris
Comment options

@beppo-ivel
Comment options

Answer selected by beppo-ivel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants