Guest User

Untitled

a guest
Jun 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Device Properties Example</title>
  5.  
  6.     <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
  7.     <script type="text/javascript" charset="utf-8">
  8.  
  9.     // Wait for PhoneGap to load
  10.     //
  11.     document.addEventListener("deviceready", onDeviceReady, false);
  12.     document.addEventListener("pause", onPause, false);
  13.  
  14.     var watchID = null;
  15.  
  16.     // PhoneGap is ready
  17.     //
  18.     function onDeviceReady() {
  19.         // Update every 3 seconds
  20.         var options = { frequency: 3000 };
  21.         watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
  22.     }
  23.  
  24.     // onSuccess Geolocation
  25.     //
  26.     function onSuccess(position) {
  27.         var element = document.getElementById('geolocation');
  28.         element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
  29.                             'Longitude: ' + position.coords.longitude     + '<br />' +
  30.                             '<hr />'      + element.innerHTML;
  31.     }
  32.  
  33.     // clear the watch that was started earlier
  34.     //
  35.     function clearWatch() {
  36.         if (watchID != null) {
  37.             navigator.geolocation.clearWatch(watchID);
  38.             watchID = null;
  39.         }
  40.     }
  41.  
  42.     // onError Callback receives a PositionError object
  43.     //
  44.     function onError(error) {
  45.       alert('code: '    + error.code    + '\n' +
  46.             'message: ' + error.message + '\n');
  47.     }
  48.    
  49.     function onPause() {
  50.         clearWatch();
  51.     }
  52.  
  53.     </script>
  54.   </head>
  55.   <body>
  56.     <p id="geolocation">Watching geolocation...</p>
  57.     <button onclick="clearWatch();">Clear Watch</button>    
  58.   </body>
  59. </html>
Add Comment
Please, Sign In to add comment