Skip to content

Instantly share code, notes, and snippets.

@MosheBerman
Created July 24, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MosheBerman/fb6225b3294ed5842695fa3e4afac63b to your computer and use it in GitHub Desktop.
Save MosheBerman/fb6225b3294ed5842695fa3e4afac63b to your computer and use it in GitHub Desktop.
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