Created
September 15, 2017 22:22
-
-
Save filmaj/89a30995504952dabd686d5fd79e96e5 to your computer and use it in GitHub Desktop.
Revisions
-
filmaj created this gist
Sep 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ 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('device is ready'); var first_options = { enableHighAccuracy: true, maximumAge: 300000, timeout: 10000 }; var second_options = { enableHighAccuracy: false, maximumAge: 300000, timeout: 6000 }; var did_second = false; var second_attempt = function() { if (!did_second) { did_second = true; navigator.geolocation.getCurrentPosition(function(position) { app.receivedEvent('second success!'); alert('second! 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'); }, function onError(error) { app.receivedEvent('second FAIL'); alert('second! code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); }, second_options); } }; navigator.geolocation.getCurrentPosition(function(position) { app.receivedEvent('first success!'); alert('first! 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'); second_attempt(); }, function onError(error) { app.receivedEvent('first FAIL'); alert('first! code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); second_attempt(); }, first_options); setTimeout(function() { }, 30000); }, // Update DOM on a Received Event receivedEvent: function(evt) { var parentElement = document.getElementById('deviceready'); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); receivedElement.innerHTML = evt; console.log('Received Event: ' + evt); } }; app.initialize();