Location is turned on the phone.It takes 5 to 20 seconds when getCurrentPosition method is called.
Code :
var app = {
// Application Constructor
initialize: function()
{ document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); }
,
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function()
{ this.receivedEvent('deviceready'); }
,
// 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); navigator.geolocation.getCurrentPosition(onSuccess, onError); }
};
var onSuccess = function(position)
{ alert('Latitude: ' + position.coords.latitude + '\n' + 'Longitude: ' + position.coords.longitude + '\n' + 'Altitude: ' + position.coords.altitude + '\n' + 'Accuracy: ' + position.coords.accuracy + '\n' + 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' + 'Heading: ' + position.coords.heading + '\n' + 'Speed: ' + position.coords.speed + '\n' + 'Timestamp: ' + position.timestamp + '\n'); }
;
// onError Callback receives a PositionError object
//
function onError(error)
{ alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); }
app.initialize();