Skip to content

Instantly share code, notes, and snippets.

@levic
Last active August 29, 2015 14:10
Show Gist options
  • Save levic/6a5d4b9c1b6ea1fcd147 to your computer and use it in GitHub Desktop.
Save levic/6a5d4b9c1b6ea1fcd147 to your computer and use it in GitHub Desktop.
Minimal cordova location services example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
</head>
<body>
<div>
<p style="margin-top: 60px;" class="state">State: <span class="data"></span></p>
<input class="start" type="button" value="Start" />
<input class="stop" type="button" value="Stop" />
</div>
<script type="text/javascript" src="cordova.js"></script>
<!--<script type="text/javascript" src="js/jquery.js"></script>-->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript">
document.addEventListener('deviceready', function() {
$('.start').click(function() {
geowatcherMinimal.start();
});
$('.stop').click(function() {
geowatcherMinimal.stop();
});
}, false);
var geowatcherMinimal = (new function() {
var me = this;
var handle = null;
var geoOptions = {
enableHighAccuracy : true,
timeout : 10000,
maximumAge : 10000
};
var geoTick = function(position) {
$('.state .data').text(position.coords.latitude + ', ' + position.coords.longitude);
};
var geoTickError = function(error) {
$('.state .data').text(error);
me.stop();
};
me.start = function() {
me.stop();
handle = navigator.geolocation.watchPosition(geoTick, geoTickError, geoOptions);
};
me.stop = function() {
if (handle) {
navigator.geolocation.clearWatch(handle);
handle = null;
}
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment