Remove GeoLocation Event Listener #13554
Answered
by
ewanharris
beppo-ivel
asked this question in
Q&A
-
If I open app the event-listener is added and the function views/index.xml
lib/util.js
controllers/index.js
|
Beta Was this translation helpful? Give feedback.
Answered by
ewanharris
Aug 31, 2022
Replies: 1 comment 3 replies
-
@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(); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
beppo-ivel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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