Here is the code
document.addEventListener(“deviceready”, loaded, false);
var watchID = null;
function loaded() {
watchID = navigator.geolocation.watchPosition(success, error);
alert("loaded");
}
function success(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />' +
'<hr>' + element.innerHTML;
}
function error(error) {
alert(error.message);
}
function clearWatch() {
if (watchID != null) {
navigator.geolocation.clearWatch(watchID);
watchID = null;
}
}