Created
February 2, 2012 18:54
-
-
Save candera/1725103 to your computer and use it in GitHub Desktop.
Test of geolocation HTML
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
function watchLocation(successCallback, errorCallback) { | |
successCallback = successCallback || function(){}; | |
errorCallback = errorCallback || function(){}; | |
// Try HTML5-spec geolocation. | |
var geolocation = navigator.geolocation; | |
if (geolocation) { | |
// We have a real geolocation service. | |
try { | |
function handleSuccess(position) { | |
successCallback(position.coords); | |
} | |
geolocation.watchPosition(handleSuccess, errorCallback, { | |
enableHighAccuracy: true, | |
maximumAge: 5000 // 5 sec. | |
}); | |
} catch (err) { | |
errorCallback(); | |
} | |
} else { | |
errorCallback(); | |
} | |
} | |
function init() { | |
watchLocation(function(coords) { | |
document.getElementById('test').innerHTML = 'coords: ' + coords.latitude + ',' + coords.longitude; | |
}, function(e) { | |
document.getElementById('test').innerHTML = 'error:' + e.message; | |
}); | |
} | |
</script> | |
</head> | |
<body onload="init()"> | |
<div id="test">Loading...</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment