如何在IONIC FRAMEWORK中启用或不启用GPS服务 [英] How to check GPS service is enabled or not in IONIC FRAMEWORK
问题描述
我正在开发一个应用程序,它具有跟踪用户位置的功能,因为我使用了Cordova Geolocation插件,但在此之前必须检查GPS是否启用。
I am developing an application which has a facility to track user location for that I used Cordova Geolocation plugin but, before that have to check GPS is enable or not.
推荐答案
在Cordova Geolocation插件中有以下方法:
In the Cordova Geolocation plugin there is the method:
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
这就是你所需要的。如果禁用了地理定位,则会调用 geolocationError
函数。 文档说在Android上你需要指定一个超时
在 geolocationOptions
中,以便调用 geolocationError
函数。所以你必须这样做:
That is all you need. If geolocation is disabled, the geolocationError
function is called. The docs say that on android you need to specify a timeout
in the geolocationOptions
in order to make the geolocationError
function be called. So you would have to do it like so:
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
{timeout:3000});
在未收到后调用 geolocationError
函数3秒后地理定位(=地理位置关闭)。
To call the geolocationError
function after not receiving a geolocation (= geolocation turned off) after 3 seconds.
这篇关于如何在IONIC FRAMEWORK中启用或不启用GPS服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!