Skip to content

Instantly share code, notes, and snippets.

@tejo
Created February 7, 2012 10:16
Show Gist options
  • Select an option

  • Save tejo/1758953 to your computer and use it in GitHub Desktop.

Select an option

Save tejo/1758953 to your computer and use it in GitHub Desktop.
geocation class
GeoLocator = (function() {
function GeoLocator() {
this.watch = __bind(this.watch, this); this.watcher = navigator.geolocation.watchPosition(this.watch, this.geo_error, {
enableHighAccuracy: true,
frequency: 3000,
maximumAge: 2000,
timeout: 27000
});
this.map = new Map(document.getElementById("map"));
}
GeoLocator.prototype.watch = function(position) {
this.coords = position.coords;
if (this.coords.accuracy > 50) {
return $("#geolocation").html("getting location");
} else {
if (this.map.map_visible) {
this.map.moveMarker(this.coords);
this.map.center(this.coords);
} else {
this.map.init(this.coords);
}
return $("#geolocation").html("Latitude: " + this.coords.latitude + "<br />Longitude: " + this.coords.longitude + " <br />Accuracy: " + this.coords.accuracy + "<br />");
}
};
GeoLocator.prototype.geo_error = function() {
return alert("geolocation not available");
};
GeoLocator.prototype.stop = function() {
return navigator.geolocation.clearWatch(this.watcher);
};
return GeoLocator;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment