如果 gps 关闭,离子显示错误 [英] Ionic display error if gps is turned off

查看:41
本文介绍了如果 gps 关闭,离子显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试确定是否有人在 Ionic/Cordova 中关闭了 GPS 时遇到了一点问题.

Got a bit of an issue trying to determine if someone has their GPS turned off in Ionic/Cordova.

这是我目前正在尝试做的事情,这在浏览器中可以正常工作,但在 android 上却不行.

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');
});

另一件事是有人知道是否可以提示使用 Ionic/cordova 打开 GPS?

Another thing is does anyone know if its possible to give a prompt to turn on GPS with Ionic/cordova?

有人有什么想法吗?

推荐答案

请添加这个 插件,

Please add this plugin,

cordova plugin add cordova.plugins.diagnostic

1.确定是否有人在 Ionic/Cordova 中关闭了 GPS

控制器

if (window.cordova) {
    cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
        alert("Location is " + (enabled ? "enabled" : "disabled"));
    }, function(error) {
        alert("The following error occurred: " + error);
    });
}

2.提示开启GPS

控制器

if (window.cordova) {
    cordova.plugins.diagnostic.switchToLocationSettings();
}

这篇关于如果 gps 关闭,离子显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆