Last active
December 16, 2015 20:09
-
-
Save genejones/5490153 to your computer and use it in GitHub Desktop.
Determine current location using HTML5 techniques.
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
//made with help from https://developer.mozilla.org/en-US/docs/DOM/window.navigator.geolocation.getCurrentPosition | |
function setPositionFromCurrent(){ | |
//this requires HTML5 | |
if (!!navigator.geolocation){ | |
navigator.geolocation.getCurrentPosition(function (position){ | |
var coords = position.coords; | |
console.log('Latitude : ' + coords.latitude); | |
console.log('Longitude: ' + coords.longitude); | |
window.lat = coords.latitude; | |
window.lon = coords.longitude; | |
}, function (error){alert("Couldn't set geo-location automatically due to the following: "+error.message);}, | |
{enableHighAccuracy:true, timeout: 5000, maximumAge: 30} | |
//if the device has GPS or another high accuracy device, use that | |
//but don't take more than 5seconds to do so | |
//cached locations are OK, but they must be less than 30 seconds old | |
); | |
} | |
else{ | |
alert("Your browser does not support geolocation. Try again with a new version of Chrome 5+, Firefox 3.5+, Internet Explorer 9+, Safari 5+, or Opera 10.60+"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment