Skip to content

Instantly share code, notes, and snippets.

@shazron
Created August 30, 2012 21:43
Show Gist options
  • Select an option

  • Save shazron/3541951 to your computer and use it in GitHub Desktop.

Select an option

Save shazron/3541951 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
<title>Hello World</title>
<script type="text/javascript" src="cordova-2.1.0rc1.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, true);
var watchID;
function onDeviceReady() {
watchID = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 });
}
function onSuccess(position) {
try {
var element = document.getElementById('result');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Timestamp: ' + position.timestamp.getTime() + '<br />' +
'<hr />' + element.innerHTML;
} catch (e) {
alert(e);
}
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment