Page 1 of 2

Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 2:12 am
by Tommy B

I would like to stop my app from using the geolocation watch event after I press a button. This is the code that i took from Phonegap. I put it in a javascript event when a button is pushed but it doesnt seem to be working.

precode
var watchID = navigator.geolocation.watchPosition;
navigator.geolocation.clearWatch(watchID);
/code/pre


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 3:14 am
by Illya Stepanov

Hi Tommy, how you invoke the geolocation event on a page?


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 3:19 am
by Tommy B

I created a GeolocationService in the project tab. I call/start the service on "page show".


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 4:01 am
by Tommy B

So I read from the Appery Docs that you can use the following code to start the service.
codeserviceInstanceName.execute({});/code
Maybe there is a "stop" version of this?


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 4:11 am
by Tommy B

I read that there is but its only for ios not android.


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 4:29 am
by Illya Stepanov

I'm working on it. We will update.


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 1:53 pm
by Kateryna Grynko

Hi Tommy,

You don't have to stop Geolocation service component. To monitor device position you would have to call service again and again.

So you don't need the code you've found - the service defines geolocation only once when it's called, then it stops


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 6:17 pm
by Tommy B

My ultimate goal is to stop the geolocation service when the app is closed.

Currently my app is set as a mobile app so that I can access native functions. When I close the app by pressing my "home" button on my Android device the gps stays active (which is a battery killer). I have to manually "kill" the app in order to stop the gps function.

Now, if i view the app as an HTML app then the geolocation stops when the page that the app is displayed in closes.


Stop golocation "watch" with onClick event

Posted: Mon Jun 10, 2013 7:11 pm
by Maryna Brodina

Hello! It's a bug, we'll fix it. As a workaround you can create Generic service (https://getsatisfaction.com/apperyio/...) based on Geolocation, save watchID as global variable and use it to make clearWatch on button click.


Stop golocation "watch" with onClick event

Posted: Wed Jun 12, 2013 10:28 pm
by Tommy B

Ok thanks. Any idea on when the bug will be fixed?