Start a new topic

Cordova - stopping user's geolocation after closing the view

Cordova - stopping user's geolocation after closing the view

Hi Wikitude Staff,

I'm currently testing around the Wikitude Cordova Plugin in an Ionic application (a cordova framework), which is deployed on a physical Android-powered device (Samsung S4 min. It's quite an impressive plugin and overall, everything's working well so far.

But (and that's why i'm posting now) there's one thing that's bothering me.

When I load my example world, which requires the geo feature, the user's location is correctly tracked, as expected. When I close my world (either with the Android back button or a custom "Close" button), the ARview seems to be properly destroyed. But the tracking still continues, even when I put the app in background. The only way for me to stop it is to kill it via the android app manager.

I've downloaded, installed, launched and tested your Sample App on the same device and I could see that, there, the user's location is correctly stopped when any of the views requiring it is closed. I've checked the code of these samples and couldn't find anything resembling a manual stoping of this location tracking. So I'm assuming that it's being stopped when the view is destroyed. Except that it's not working in my example App.

Am I missing something ? Is there a way for me to manually stop the location tracking when the view is destroyed ?

You'll find in attachments both my app.js (the main js file of my Ionic App) and my ar.js (the main js of my Wikitude World).

(P.S. : I initially wanted to put some screenshots in my message but couldn't find how to achieve that. The "image" button on the text editor did not gave me any option to upload images)

Thanks in advance !

Hi Mathias,
Thx for your detailed description!
It seems that our Cordova Plugin for Android does not correctly pauses location updates. We will have a look at it but if you are familiar with Android development and need a fix right away, you could have a look at the plugin yourself and maybe add the missing code.

Best regards


Hi Andreas,

I don't need a fix right away, I'm merely in a test and exploratory phase (I'm not very familiar with Android development anyway).

But, as I said in my initial comment, when I try your Cordova Sample App on my phone, everything's just working smoothly. Each time I quit an example that requires user's location updates (say the Adding Radar sample), the app correctly stops updating the location. So I don't think the problem is related to your Cordova Android plugin (again, it works fine on your Cordova Sample App).

I was thinking maybe it could be related to the fact that I've implemented your plugin in an Ionic application ? Though this framework is build on top of Cordova, maybe there's something causing your Cordova plugin to not work as expected. I don't know, just a thought ;)

Anyway, I was also assuming that your plugin uses


when locating the user. If it's the case, then there should be a watchID somewhere that could be manually accesed in order to stop the location updates. That could "solve" the issue, at least temporarily.

Am I completely wrong with this hypothesis ?

Thanks for your answer (and the next ones).

Hi Andreas,

For what it's worht, I have some informations about my app behavior that could help find and (hopefully) resolve the problem.

Here's what's happenning...

First case: I launch the app for the first time and land on my index page. I click on the "Load World" button and loads the AR World, which starts the user's location tracking. I close the AR View using the Android back button : the view is properly closed and the tracking is stopped. I click again on the "Load World" buttons and loads again the AR World, which restart the tracking. If I want to close the AR View with the back button again, the app is put on background and the tracking still go on. From now on, whatever I do, the tracking is continuously on, until the app is killed.

Second case: I launch the app for the first time and load the World (and so the user's location tracking). I close the AR View using a custom "close" button (that calls the close() function), which is displayed on the HTML page overlaying the camera feed. The view is closed, but the tracking continues until the app is killed.

Hope that helps!

N.B.: Using your Cordova Sample App, I was not able to reproduce any of these cases. I think that the problem is coming from Ionic. Maybe there's a component of the framework that's interfeering with the expected close behavior... That, or my implementation is kinda buggy...

Isn't there any mean to programmatically stops the user's location tracking ?



Hi Mathias,
Location updates are not handled in JS, so there is no watchId. It is implemented in our Java plugin. Location updates are resumed/paused once the onResume/onPause Android lifecycle methods are called. Looks like Ionic doesn't call these methods.
You can try to manually call these functions. Our Cordova plugin exposes these two methods in JS, so if there is a way to know when the application pauses/resumes in Ionic, simply call our Plugin onPause/onResume function.

Best regards


Hi Andreas,

Thanks for this insight, I will look up to that some time soon.

Still, that doesn't explain why the location update is not stopped when I call your WikitudePlugin.close() function with a custom button.

But considering what you've just said to me, I should be able to call the onPause() method right after the WikitudePlugin.close() method.

I'll write again if I have any more question regarding this matter.

Thanks for your time ;)
Login or Signup to post a comment