Javascript 检查node.js+;科尔多瓦+;ionic应用程序,如果GPS被禁用,则通知用户并指导他进行设置以打开GPS
我正在使用node、angular、ionic和cordova创建一个移动应用程序,它应该与android版本4.0.3和更高版本兼容。我希望应用程序弹出一个通知,如果GPS被用户禁用。此外,通知还应具有取消选项和指向GPS设置的选项,以便用户手动打开GPS 为了做到这一点,我尝试了以下npm插件,但没有一个适合我。当我尝试它们时,只有飞溅屏幕出现,其他什么都没有Javascript 检查node.js+;科尔多瓦+;ionic应用程序,如果GPS被禁用,则通知用户并指导他进行设置以打开GPS,javascript,node.js,cordova,ionic-framework,Javascript,Node.js,Cordova,Ionic Framework,我正在使用node、angular、ionic和cordova创建一个移动应用程序,它应该与android版本4.0.3和更高版本兼容。我希望应用程序弹出一个通知,如果GPS被用户禁用。此外,通知还应具有取消选项和指向GPS设置的选项,以便用户手动打开GPS 为了做到这一点,我尝试了以下npm插件,但没有一个适合我。当我尝试它们时,只有飞溅屏幕出现,其他什么都没有 cordova.plugins.diagnostic cordova插件fastrde checkgps cordova插件and
- cordova.plugins.diagnostic
- cordova插件fastrde checkgps
- cordova插件android gpsdetect
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
alert("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
alert("error");
});
})
我做错了什么?我遵循我的代码。有人能告诉我怎么做吗?有一个很好的cordova插件。它不仅会检查位置是否已打开,而且您还可以要求不同的精度并打开它们,而无需将用户重定向到其位置设置 问题解决了。 我将下面的代码部分添加到了错误的位置
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
alert("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
alert("error");
});
它不应该在$ionicPlatform.ready函数中调用,因为在设备完全准备好之前,插件没有定义。我把它放在我的一个控制器里,它工作了
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
alert("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
alert("error");
});