angularjs - Cordova Angularjs 请求 GPS

标签 angularjs cordova gps

我编写了一个需要 GPS 的应用程序。 如果 GPS 关闭,我如何要求用户打开 GPS,例如谷歌地图?经过一段时间的谷歌搜索,我发现没有什么可比的...... 我的另一个问题是,当 GPS 关闭时,为什么我会收到“使用位置? - 2”?我想,如果 GPS 关闭,$window.navigator.geolocation 就是 false?

Google Maps

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 。我正在使用它。 (至少要调用位置设置)。

关于angularjs - Cordova Angularjs 请求 GPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35165351/

相关文章:

javascript - Angularjs:从本地json文件加载内容

iphone - 将 GPS 坐标转换为坐标平面

ios - 如何添加指向 map 上图钉的 GPS?

javascript - peer.js webrtc >> 在运行时改变流

javascript - 将图像另存为 Base64 时应用程序在 Ionic View 中崩溃

android - 如何仅通过 GPS 读数确定方向并以 360 度显示?

javascript - AngularJS UI - 如果存在多个 div,则单击按钮会折叠单个 div

css - Angular CSS ngAnimate 翻译给开发人员

javascript - Angular.js 路由不起作用

android - 错误 - Google map Cordova 插件安装