Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2012 18:33
geo-test
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<input type="button" value="Show position" onclick="show()">
<div id="data">
</data>
<script language="javascript">
function showPos(position) {
var htmlStr = '<p>'+ 'Latitude: ' + position.coords.latitude + '<br />'
+ 'Longitude: ' + position.coords.longitude + '<br />'
+ '</p>';
document.getElementById('data').innerHTML = htmlStr;
}
function error() {
alert('Could not get your location.');
}
function show(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPos, error, {timeout:20000});
//navigator.geolocation.watchPosition(showPos, error, {enableHighAccuracy:true, //maximumAge:30000, timeout:20000});
} else {
alert('No support for geolocation')
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment