Created
February 11, 2014 23:27
-
-
Save kennethkoontz/8946571 to your computer and use it in GitHub Desktop.
This file contains 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(){ | |
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