Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function Locator(successCallback, errorCallback)
  2. {
  3. this.success = (location) =>
  4. {
  5. console.dir(location);
  6. this.pauseLocationUpdates();
  7.  
  8. successCallback(location);
  9.  
  10. };
  11.  
  12. this.error = () =>
  13. {
  14. console.log("Failed to access location");
  15.  
  16. errorCallback();
  17. };
  18.  
  19. this.pauseLocationUpdates = () =>
  20. {
  21. if(this.watchID !== null)
  22. {
  23. navigator.geolocation.clearWatch(this.watchID);
  24. this.watchID = null;
  25. }
  26. };
  27.  
  28. this.options = {
  29. enableHighAccuracy: true,
  30. maximumAge : 30000,
  31. timeout : 27000
  32. };
  33.  
  34. this.locate = () =>
  35. {
  36. var browserSupportsLocation = "geolocation" in navigator;
  37.  
  38. if (browserSupportsLocation)
  39. {
  40. this.watchID = navigator.geolocation.watchPosition(this.success, this.error, this.options);
  41. }
  42. else
  43. {
  44. this.error();
  45. }
  46. };
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement