Skip to content

Instantly share code, notes, and snippets.

@kennethkoontz
Created February 11, 2014 23:27
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 kennethkoontz/8946571 to your computer and use it in GitHub Desktop.
Save kennethkoontz/8946571 to your computer and use it in GitHub Desktop.
(function(){
var Geolocation = {
coordinates: {long:null, lat:null, timestamp:null, accuracy:null},
capable: function(){
//return false;
return Modernizr.geolocation?true:false;
},
getLatitude: function(){
return coordinates.lat.toString();
},
getLongitude: function(){
return coordinates.long.toString();
},
positionErr: function(err){
console.log(err);
console.log(err.code); // 1:user denied access, 2:satellites down, 3:timeout
console.log(err.message);
},
raiseError: function(){
alert("Your browser doesn't support location information.");
return false;
},
setCoordinates: function(){
if (this.capable()) {
navigator.geolocation.getCurrentPosition(function(pos){
this.coordinates.lat = pos.coords.latitude;
this.coordinates.long = pos.coords.longitude;
console.log("attempt finished");
console.log("lat: "+coordinates.lat+" long: "+lcoordinates.ong);
}, this.positionErr);
console.log("getCurrentPosition may have completed");
}
else{
this.raiseError();
}
return;
},
getCoordinates: function(position){
},
lookup: function(){
console.log(this.coordinates.lat);
if (this.coordinates.lat == null || this.coordinates.long == null) {
alert("no location data.");
this.setCoordinates();
}
else{
alert("location data already exists");
console.log("coordinates: long:"+this.coordinates.long+" lat:"+this.coordinates.lat);
}
}
}
window.Geo = Geolocation;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment