This page allows you to monitor the geo location of the android device.
Latitude: Waiting for latitude
Longtitude: Waiting for longtitude
Altitude: Waiting for altitude
Accuracy: Waiting for accuracy
Heading: Waiting for heading
Speed: Waiting for speed
This demo is using the cordova-plugin-geolocation plugin. For more information click here:
var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};
GSW.Tests.onDeviceReady = function() {
// Cordova is now initialized. Have fun!
console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);
// onError Callback receives a PositionError object
GSW.Tests.onError = function(error) {
if(error.code == 1){
alert('This error could be one of two options \n 1. Geolocation permissions are not enabled. \n 2. You have accessed this site via HTTP, please use HTTPS.')
}else{
alert('Geolocation:' + '\n' +
'code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
}
GSW.Tests.onSuccess = function(position) {
console.log('Geolocation:' +
'Latitude: ' + position.coords.latitude + ' ' +
'Longitude: ' + position.coords.longitude + ' ' +
'Altitude: ' + position.coords.altitude + ' ' +
'Accuracy: ' + position.coords.accuracy + ' ' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + ' ' +
'Heading: ' + position.coords.heading + ' ' +
'Speed: ' + position.coords.speed + ' ' +
'Timestamp: ' + position.timestamp);
document.getElementById("geo_latitude").innerHTML = position.coords.latitude;
document.getElementById("geo_longtitude").innerHTML = position.coords.longitude;
document.getElementById("geo_altitude").innerHTML = position.coords.altitude;
document.getElementById("geo_accuracy").innerHTML = position.coords.accuracy;
//document.getElementById("geo_altitude_accuracy").innerHTML = position.coords.altitudeAccuracy;
document.getElementById("geo_heading").innerHTML = position.coords.heading;
document.getElementById("geo_speed").innerHTML = position.coords.speed;
}
GSW.Tests.watchPosition = function() {
navigator.geolocation.watchPosition(GSW.Tests.onSuccess, GSW.Tests.onError, { timeout: 30000, enableHighAccuracy: true });
}
document.getElementById("start").addEventListener("click", GSW.Tests.watchPosition);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);