Created
July 24, 2017 16:51
-
-
Save MosheBerman/fb6225b3294ed5842695fa3e4afac63b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Locator(successCallback, errorCallback) | |
{ | |
var _this = this; | |
this.success = function(location) | |
{ | |
console.dir(location); | |
_this.pauseLocationUpdates(); | |
successCallback(location); | |
}; | |
this.error = function() | |
{ | |
console.log("Failed to access location"); | |
errorCallback(); | |
}; | |
this.pauseLocationUpdates = function() | |
{ | |
if(_this.watchID !== null) | |
{ | |
navigator.geolocation.clearWatch(_this.watchID); | |
_this.watchID = null; | |
} | |
}; | |
this.options = { | |
enableHighAccuracy: true, | |
maximumAge : 30000, | |
timeout : 27000 | |
}; | |
this.locate = function() | |
{ | |
var browserSupportsLocation = "geolocation" in navigator; | |
if (browserSupportsLocation) | |
{ | |
_this.watchID = navigator.geolocation.watchPosition(_this.success, _this.error, _this.options); | |
} | |
else | |
{ | |
_this.error(); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment