Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Stop golocation "watch" with onClick event

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

Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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

Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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?

Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Stop golocation "watch" with onClick event

I'm working on it. We will update.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Stop golocation "watch" with onClick event

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

Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Stop golocation "watch" with onClick event

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.

Tommy B
Posts: 0
Joined: Sat Sep 15, 2012 3:39 am

Stop golocation "watch" with onClick event

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

Return to “Issues”