简体   繁体   English

在Cordova Android中检查GPS状态(打开/关闭)

[英]Check GPS state (on/off)in cordova android

I am successfully implement the geolocation using this ( https://github.com/apache/cordova-plugin-geolocation ) for cordova,however the gps is turned off in the phone onerror function is never called.Is there any another way to check the gps is turned on or off.Here is my code 我使用此( https://github.com/apache/cordova-plugin-geolocation )成功实现了科尔多瓦号的地理位置,但是从未调用过电话onerror功能中的gps。请问还有其他方法可以检查gps已开启或关闭。这是我的代码

navigator.geolocation.getCurrentPosition(function (position) {
//getting location
 lat=position.coords.latitude;
long=position.coords.longitude;

}, function (error) {
        //when gps is off it is never executed
         alert('Unable to get location: ' + error.message);

        });

UPDATE UPDATE

onerror is executed in SONY XPERIA T ,but not in other devices ( Micromax,Samsung,Motog ) SONY XPERIA T中执行onerror ,但在其他设备( Micromax,Samsung,Motog )中不执行

I do not know if this is what you want, but I am using this plugin which works well for me 我不知道这是否是您想要的,但是我正在使用这个对我来说效果很好的插件

https://github.com/mablack/cordova-diagnostic-plugin https://github.com/mablack/cordova-diagnostic-plugin

I think the Geolocation API does not give you an error if the GPS is on/off, just a timeout error if it is not able to get a lock in the time limit you specify, but I tested it a while ago and I might be mistaking. 我认为,如果GPS处于打开/关闭状态,Geolocation API不会给您错误,如果无法锁定您指定的时间限制,则只会显示超时错误,但是我前一段时间进行了测试,我可能会误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM