gps关闭时离子显示错误 [英] Ionic display error if gps is turned off
问题描述
有一个问题想要确定是否有人在Ionic / Cordova中关闭了他们的GPS。
这里是我现在想做的,这在浏览器很好,但不是在Android上。
navigator.geolocation.getCurrentPosition(function(pos){},function(err){
alert('我们无法确定您的位置,请打开您的GPS / Location services');
});另一件事是任何人都知道如果它可能提示打开GPS与Ionic / cordova的?
任何人都有任何想法?
解决方案 href =https://github.com/dpa99c/cordova-diagnostic-plugin> 此 插件,
cordova插件add cordova.plugins.diagnostic
1。确定某人是否在Ionic / Cordova中关闭了GPS
Contoller
strong>
if(window.cordov){
cordova.plugins.diagnostic.isLocationEnabled(function
alert(Location is+(enabled?enabled:disabled));
},function(error){
alert(发生以下错误: );
});
}
2.提示打开GPS
控制器
if(window.cordova){
cordova.plugins.diagnostic.switchToLocationSettings();
}
Got a bit of an issue trying to determine if someone has their GPS turned off in Ionic/Cordova.
Here is what I am trying to do at the moment, this works in the browser fine but not on android.
navigator.geolocation.getCurrentPosition(function(pos) {}, function(err) {
alert('We were unable to determine your location, please turn on your GPS/Location services');
});
Another thing is does anyone know if its possible to give a prompt to turn on GPS with Ionic/cordova?
Anyone got any ideas?
解决方案 Please add this plugin,
cordova plugin add cordova.plugins.diagnostic
1.Determine if someone has their GPS turned off in Ionic/Cordova
Contoller
if (window.cordova) {
cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
alert("Location is " + (enabled ? "enabled" : "disabled"));
}, function(error) {
alert("The following error occurred: " + error);
});
}
2.Giving a prompt to turn on GPS
Controller
if (window.cordova) {
cordova.plugins.diagnostic.switchToLocationSettings();
}
这篇关于gps关闭时离子显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!