Cordova Angularjs要求GPS [英] Cordova Angularjs ask for GPS

查看:164
本文介绍了Cordova Angularjs要求GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程一个应用程序,我需要GPS。
如果GPS关闭,我怎么能要求用户打开GPS,如google地图?过了一段时间的googleing,我发现没有可比性...
我的其他问题是,为什么我得到使用位置? - 2,当GPS关闭时?我想,如果GPS关闭,$ window.navigator.geolocation是false?

I program an app where I need GPS. If the GPS is off, how can I ask the user to turn on GPS, like google maps? After a while of googleing I found nothing compareable... My other question is, why I get "Use location? - 2", when the GPS is off? I thought, if the GPS is off, $window.navigator.geolocation is false?

controller.js

controller.js

if ($window.navigator && $window.navigator.geolocation) { 
    function success(pos) {
        $rootScope.position = { x: pos.coords.latitude, y: pos.coords.longitude };
    }
    function fail(error) {
        alert("Use location? - 2");
    }
     $window.navigator.geolocation.getCurrentPosition(success, fail, { maximumAge: 500000, enableHighAccuracy: true, timeout: 6000 });
} else {
    alert("Use location? - 1");
}


推荐答案

以帮助您获得,如果你的GPS是启用。然后您可以要求用户更改位置设置。其中一个是诊断插件 https://www.npmjs.com/package/cordova。 plugins.diagnostic 。我使用它。 (至少调用位置设置)。

There are many plugins that promess to help you get if your gps is enable. Then you can ask the user to change Location Settings. One of them is the Diagnostics Plugin https://www.npmjs.com/package/cordova.plugins.diagnostic . I am using it. (al least to call the Location Settings).

这篇关于Cordova Angularjs要求GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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