Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created November 6, 2012 06:35
Show Gist options
  • Save ahomu/4023029 to your computer and use it in GitHub Desktop.
Save ahomu/4023029 to your computer and use it in GitHub Desktop.
Geolocation test
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hmmm...?</title>
<meta name="viewport" content="width=device-width">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<style type="text/css">
#js-geoloc {
font-size: 150%;
padding: 20px;
}
</style>
<script type="text/javascript">
$(function() {
var $latlng = $('#js-latlng');
$('#js-geoloc').bind('touchend', function() {
$latlng.text('location updating....');
navigator.geolocation.getCurrentPosition(
onSuccess, onError, {maximumAge: 600000, timeout: 30}
);
});
function onSuccess(pos) {
$latlng.text(pos.coords.latitude + ' : ' +pos.coords.longitude);
}
function onError() {
alert('error');
}
});
</script>
</head>
<body>
<button id="js-geoloc">getCurrentPosition</button>
<p id="js-latlng">location updating....</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment