I use plugin cordova Geolocation for ionic 2 but I need to know if the GPS is enabled or disabled . I don't know how make this.
Please Help Me ;) Thanks!
The diagnostic plugin has your back with a lot of functionality to check for GPS mode, location status and more. Check the included link to know more about it.
import { Diagnostic } from '@ionic-native/diagnostic';
constructor(private diagnostic: Diagnostic) { }
...
let successCallback = (isAvailable) => { console.log('Is available? ' + isAvailable); };
let errorCallback = (e) => console.error(e);
this.diagnostic.isLocationEnabled().then(successCallback).catch(errorCallback);
// only android
this.diagnostic.isGpsLocationEnabled().then(successCallback, errorCallback);
You can also use the location-accuracy plugin which is lighter but it's missing other options available on the diagnostic plugin. I'm currently using this plugin to enable gps on android and to set the mode. I'll suggest to also look at the doc of this plugin.
I had good luck with this plugin
http://devfanaticblog.com/background-geolocation-with-apache-cordova/
cordova plugin add cordova-plugin-mauron85-background-geolocation
Might be extreme overkill for what you need though. You could always just call getcurrentposition() and check if you get a valid result.
navigator.geolocation.getCurrentPosition(success[, error[, options]])
I am not certain how iPhones treat it, but Android can be downright evil now. Because the user will be prompted to give permission to their GPS if you ask to use it. If they choose no, then it could be enabled, but unavailable to you. You also can't easily tell what precision you are getting. You might be getting wifi or mobile location instead of GPS location.
This plugin covers all those scenarios, however, it has an odd bug that it doesn't work properly in the android emulator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With