科尔多瓦Angularjs要求GPS [英] Cordova Angularjs ask for GPS

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

问题描述

我编写一个应用程序,我需要GPS。
如果GPS是关闭的,我怎么能要求用户打开GPS,像谷歌地图?过了一会googleing后,我什么都没有发现compareable ...
我的另一个问题是,为什么我得到使用地点 - ?2,当GPS处于关闭状态?我想,如果GPS关闭,$ window.navigator.geolocation是假的?

谷歌地图

controller.js

 如果($ window.navigator&放大器;&安培; $ window.navigator.geolocation){
    函数成功(POS){
        $ rootScope.position = {X:pos.coords.latitude,Y:pos.coords.longitude};
    }
    功能失效(错误){
        警报(使用地点 - 2?);
    }
     $ window.navigator.geolocation.getCurrentPosition(成功,失败,{maximumAge:500000 enableHighAccuracy:真,超时:6000});
}其他{
    警报(使用地点 - 1?);
}


解决方案

有这PROMESS帮助您得到,如果你的GPS是使许多插件。然后,你可以要求用户改变位置设置。其中之一是诊断插件 https://www.npmjs.com/package/cordova。 plugins.diagnostic 。我使用它。 (人至少要调用位置设置)。

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

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

解决方案

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).

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

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