Framework或Cordova中以编程方式启用和禁用GPS

Framework或Cordova中以编程方式启用和禁用GPS

本文介绍了如何在Ionic Framework或Cordova中以编程方式启用和禁用GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单。我需要一种方法来使用Ionic应用程序内的按钮打开和关闭GPS。我查看了文档并阅读了这个ng-cordova插件但他们似乎没有这个功能。我只是遗漏了一些东西,或者在Ionic Framework中这是否可能?谢谢!

My problem is simple. I need a way to turn on and off GPS using a button inside an Ionic app. I've check the docs and read this ng-cordova plugin http://ngcordova.com/docs/plugins/geolocation/ but they don't seem have this funcction. Am I just missing something or is this even possible in Ionic Framework? Thanks!

推荐答案

据我所知,无法从你的应用程序直接禁用GPS。

As far as I'm aware there isn't the ability to directly disable GPS from your app.

如果您尝试允许用户禁用GPS,我通过向用户添加 localStorage 的设置来实现此目的可以更改我的应用程序中的设置页面。每次我在我的位置工厂检查GPS时,如果设置被禁用,我会检查设置并运行错误回调。

If you are trying to allow the user to disable GPS, I achieved this by adding a setting to localStorage that the user can change on the settings page in my app. Every time I check for GPS in my location factory, I check against the setting and run the error callback if the setting was disabled.

可能会有某种调用可以自动打开设备上的位置设置页面,因为我看到其他应用程序这样做了,但我不确定Cordova / Ionic是否支持它。

There may be some sort of call which can automatically open the location settings page on your device as I have seen other apps do this, but I'm not sure if that is supported in Cordova/Ionic yet.

这篇关于如何在Ionic Framework或Cordova中以编程方式启用和禁用GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:08