phonegap: how to check if gps is enabled

前端 未结 3 1197
耶瑟儿~
耶瑟儿~ 2021-02-06 09:01

I want to show an alert saying that \"Please turn on your GPS\".

How can I get GPS status using phonegap?

I have used following code but I don\'t get any alert m

3条回答
  •  迷失自我
    2021-02-06 09:22

    The answer to your question is below.

    You cannot check *if gps is enabled*

    You can set a timeout and get the timeout. You can do this by setting the timeout parameter in the geolocationoptions parameter. (which you did not use)

    From the documentation

    • timeout: The maximum length of time (milliseconds) that is allowed to pass from the call to navigator.geolocation.getCurrentPosition or geolocation.watchPosition until the corresponding geolocationSuccess callback executes. If the geolocationSuccess callback is not invoked within this time, the geolocationError callback is passed a PositionError.TIMEOUT error code. (Note that when used in conjunction with geolocation.watchPosition, the geolocationError callback could be called on an interval every timeout milliseconds!) (Number)

    WAIT I WAS WRONG

    There is now a plugin that checks to see if the GPS is turned on.

    In fact, more than one.

    • https://www.npmjs.com/package/cordova-plugin-fastrde-checkgps
    • https://www.npmjs.com/package/cordova-plugin-android-gpsdetect

提交回复
热议问题