Guest User

Untitled

a guest
Aug 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Call phonegap API from external page
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>Device Properties Example</title>
  6.  
  7. <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
  8. <script type="text/javascript" charset="utf-8">
  9. // Wait for PhoneGap to load
  10. //
  11. document.addEventListener("deviceready", onDeviceReady, false);
  12.  
  13. // PhoneGap is ready
  14. //
  15. function onDeviceReady() {
  16.  
  17. navigator.geolocation.getCurrentPosition(onSuccess, onError);
  18. }
  19.  
  20. // onSuccess Geolocation
  21. //
  22. function onSuccess(position) {
  23. var element = document.getElementById('geolocation');
  24. element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
  25. 'Longitude: ' + position.coords.longitude + '<br />' +
  26. 'Altitude: ' + position.coords.altitude + '<br />' +
  27. 'Accuracy: ' + position.coords.accuracy + '<br />' +
  28. 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
  29. 'Heading: ' + position.coords.heading + '<br />' +
  30. 'Speed: ' + position.coords.speed + '<br />' +
  31. 'Timestamp: ' + new Date(position.timestamp) + '<br />';
  32. }
  33.  
  34. // onError Callback receives a PositionError object
  35.  
  36. function onError(error) {
  37. alert("error");
  38. }
  39.  
  40. </script>
  41. </head>
  42. <body>
  43. <p id="geolocation">Finding my geolocation...</p>
  44. </body>
  45. </html>
Add Comment
Please, Sign In to add comment