问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/36130807/how-to-check-gps-service-is-enabled-or-not-in-ionic-framework