Skip to content

Instantly share code, notes, and snippets.

@florianbachmann
Forked from shazron/phonegap_geotest.html
Created September 30, 2011 19:25
Show Gist options
  • Save florianbachmann/1254736 to your computer and use it in GitHub Desktop.
Save florianbachmann/1254736 to your computer and use it in GitHub Desktop.
Geolocation Test
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onPhoneGapGeolocationSuccess, onPhoneGapError);
var timeInSeconds = 45 * 1000;
var options = { maximumAge: timeInSeconds/2.0, timeout: timeInSeconds, enableHighAccuracy: true };
navigator.geolocation.watchPosition(onPhoneGapWatchSuccess, onPhoneGapError, options);
}
function onPhoneGapGeolocationSuccess(position) {
var newLat = position.coords.latitude,
newLon = position.coords.longitude,
newHeading = position.coords.heading;
console.log('onPhoneGapGeolocationSuccess: [' + newLat + '|' + newLon + '] + '+ newHeading);
}
function onPhoneGapError(error) {
console.log('Status: ' + error.code + '|' + error.message);
}
onPhoneGapWatchSuccess = function(position) {
var newLat = position.coords.latitude,
newLon = position.coords.longitude;
console.log('onPhoneGapWatchSuccess: [' + newLat + '|' + newLon + ']');
}
</script>
</head>
<body onload="onBodyLoad()">
<h1>Location Test</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment