Created
November 6, 2012 06:35
-
-
Save ahomu/4023029 to your computer and use it in GitHub Desktop.
Geolocation test
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> | |
<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