Guest User

Untitled

a guest
Dec 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. function init() {
  2. document.addEventListener("deviceready", watchPosition, false);
  3. }
  4.  
  5. function watchPosition() {
  6.  
  7. cordova.plugins.backgroundMode.enable(); // enable backgroundMode
  8.  
  9. // Check if location settings are turned on. Prompt user if not turned on
  10. function onRequestSuccess(success){
  11. console.log("Successfully requested accuracy: "+success.message);
  12. }
  13.  
  14. function onRequestFailure(error){
  15. console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message);
  16. if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
  17. if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
  18. cordova.plugins.diagnostic.switchToLocationSettings();
  19. }
  20. }
  21. }
  22.  
  23. cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
  24.  
  25. // start geolocation
  26.  
  27. checkPeriodically = setInterval(checkTime, 10000);
  28.  
  29. var watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
  30.  
  31. ...
Add Comment
Please, Sign In to add comment