Last active
August 29, 2015 14:03
-
-
Save sTiLL-iLL/ca6500bd187fc4125b3a to your computer and use it in GitHub Desktop.
geo locator module
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 characters
// GTRX geolocator | |
(function GTRX(window) { | |
var wndw = window, | |
var startG = function() { | |
if (wndw.navigator.geolocation) { | |
var trxLST = [], pID = "", cnt = 0, ipAddrs = ""; | |
var options = { | |
allowhighaccuracy: true, | |
timeout: 50000, | |
maximumage: 6000 | |
}; | |
var errHndlr = function(err) { | |
if (err.code == 1) { | |
console.log("Error: Access is denied!"); | |
} | |
else if (err.code == 2) { | |
console.log("Error: Position unavailable!"); | |
} | |
}; | |
wndw.onbeforeunload = function(evt) { | |
navigator.geolocation.clearWatch(pID); | |
wndw.localStorage.clear(); | |
clearInterval(iID); | |
trax = JSON.stringify({ "state": "END-TRAK" }); | |
$.getJSON("https://script.google.com/macros/s/AKfycbyOAEFG8LufiDKjoRjlRiI0U27K4WQqN1G-6jMR19GMIVL-Bc8/exec?", { | |
"p": trax, | |
"prefix": "?" | |
}, | |
function(response) { | |
console.log("END-TRACE-SUMMARY: " + JSON.stringify(response)); | |
trxLST.length = 0; | |
cnt = 0; | |
}); | |
}; | |
pID = wndw.navigator.geolocation.watchPosition(keepIt, errHndlr, options); | |
var keepIT = function(position) { | |
cnt++; | |
trxLST.push(position); | |
var p = JSON.stringify(position); | |
console.log("SUMMARY-" + cnt + ": " + p); | |
if ((cnt % 10) === 0) { | |
trax = JSON.stringify({ | |
"TRaX": trxLST | |
}); | |
var storPrev = wndw.localStorage.getItem("GEOsTORe"); | |
wndw.localStorage.setItem("GEOsTORe", storPrev + ", " + trax); | |
$.getJSON("https://script.google.com/macros/s/AKfycbyOAEFG8LufiDKjoRjlRiI0U27K4WQqN1G-6jMR19GMIVL-Bc8/exec?", { | |
"p": trax, | |
"prefix": "?" | |
}, | |
function(response) { | |
console.log("SUMMARY-" + cnt + ": " + JSON.stringify(response)); | |
}); | |
trxLST.length = 0; | |
} | |
else { console.log("Error: Position unavailable!"); }}; | |
} | |
else { console.log("Geolocation is Not Supported"); }} | |
startG(); | |
}})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment