var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
this.contents={};
this.watchID=null;
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function () {
app.receivedEvent('deviceready');
app.contents = document.getElementById('geolocation');
app.Geo();
},
onSuccess: function(position) {
app.contents.innerHTML = 'Lat : '+position.coords.latitude+', Lon : '+position.coords.longitude;
},
onError: function(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
},
Geo: function() {
watchID = navigator.geolocation.watchPosition(app.onSuccess, app.onError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });
},
// Update DOM on a Received Event
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};