Guest User

Untitled

a guest
Jan 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // Wait for Cordova to load
  2. document.addEventListener("deviceready", onDeviceReady, false);
  3.  
  4. // Cordova is ready
  5. function onDeviceReady() {
  6. console.log("Entering index.html.onDeviceReady");
  7. var networkState = navigator.network.connection.type;
  8. getPosition(networkState);
  9. }
  10.  
  11. function getPosition(networkState) {
  12. console.log("Entering getPosition function");
  13. console.log("networkState is: " + networkState);
  14. if (networkState !== null) {
  15. navigator.geolocation.getCurrentPosition(onSuccess, onError, {
  16. maximumAge : Infinity,
  17. timeout : 5000,
  18. enableHighAccuracy : true
  19. });
  20. } else {
  21. alert('Please check your network connection and try again.');
  22. }
  23. console.log("Leaving getPosition function");
  24. }
  25.  
  26. // function for lat & lng
  27. function onSuccess(position) {
  28. console.log("Entering onSuccess(position) function");
  29. console.log("Latitude is: " + position.coords.latitude);
  30. console.log("longitude is: " + position.coords.longitude);
  31. lat = position.coords.latitude;
  32. lng = position.coords.longitude;
  33. console.log("Leaving onSuccess(position) function");
  34. }
  35.  
  36. // function for lat & lng
  37. function onError(error) {
  38. console.log("Entering onError(error) function");
  39. alert('code: ' + error.code + 'n' + 'message: ' + error.message + 'n');
  40. console.log("Leaving onError(error) function");
  41. }
Add Comment
Please, Sign In to add comment