Guest User

Untitled

a guest
Oct 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. var x = document.getElementById("demo");
  2. var watchID = null;
  3. var counter = 0;
  4. function geo_success(position) {
  5. counter += 1;
  6. x.innerHTML = "Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude + ", Count: " + counter;
  7. }
  8.  
  9. function geo_error() {
  10. x.innerHTML = "Sorry, no position available.";
  11. }
  12.  
  13. var geo_options = {
  14. enableHighAccuracy: true,
  15. maximumAge: 30000,
  16. timeout: 27000
  17. };
  18.  
  19. function toggleGeolocation() {
  20. if ("geolocation" in navigator) {
  21. if (watchID == null) {
  22. watchID = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
  23. } else {
  24. navigator.geolocation.clearWatch(watchID);
  25. watchID = null;
  26. x.innerHTML = "Geolocation stopped.";
  27. }
  28. } else {
  29. x.innerHTML = "Geolocation is not supported by this browser.";
  30. }
  31. }
Add Comment
Please, Sign In to add comment