How to check GPS service is enabled or not in IONIC FRAMEWORK

别等时光非礼了梦想. 提交于 2019-12-10 23:52:27

问题


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.


回答1:


In the Cordova Geolocation plugin there is the method:

navigator.geolocation.getCurrentPosition(geolocationSuccess,
                                     [geolocationError],
                                     [geolocationOptions]);

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

To call the geolocationError function after not receiving a geolocation (= geolocation turned off) after 3 seconds.



来源:https://stackoverflow.com/questions/36130807/how-to-check-gps-service-is-enabled-or-not-in-ionic-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!