Sachin Gawai
Sachin Gawai

Reputation: 381

How to check GPS service is enabled or not in IONIC FRAMEWORK

I am developing an application which has a facility to track user location for that I used Cordova Geolocation plugin but, before that have to check GPS is enable or not.

Upvotes: 2

Views: 5033

Answers (1)

niklas
niklas

Reputation: 3011

In the Cordova Geolocation plugin there is the method:

navigator.geolocation.getCurrentPosition(geolocationSuccess,
                                     [geolocationError],
                                     [geolocationOptions]);

That is all you need. If geolocation is disabled, the geolocationError function is called. The docs say that on android you need to specify a timeout in the geolocationOptions in order to make the geolocationError function be called. So you would have to do it like so:

navigator.geolocation.getCurrentPosition(geolocationSuccess,
                                     [geolocationError],
                                     {timeout:3000});

To call the geolocationError function after not receiving a geolocation (= geolocation turned off) after 3 seconds.

Upvotes: 4

Related Questions