Computes the time at confluent from a Google Location History Export
Last active
February 18, 2016 07:42
-
-
Save tsuckow/0deaa7b28ddfdf368b35 to your computer and use it in GitHub Desktop.
Computes the time at confluent from a Google Location History Export
This file contains 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
<a href="https://takeout.google.com/settings/takeout/custom/location_history">Get your location data from here</a>, don't forget to extract the .json file. | |
<br><br> | |
Lat: <input type="number" id="lat" value="46.2854826"> Lon: <input type="number" id="lon" value="-119.2767022"> | |
<br><br> | |
<script> | |
var lat = 46.2854826; | |
var lon = -119.2767022; | |
function distance(lat1, lon1, lat2, lon2, unit) { | |
var radlat1 = Math.PI * lat1/180 | |
var radlat2 = Math.PI * lat2/180 | |
var theta = lon1-lon2 | |
var radtheta = Math.PI * theta/180 | |
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); | |
dist = Math.acos(dist) | |
dist = dist * 180/Math.PI | |
dist = dist * 60 * 1.1515 | |
if (unit=="K") { dist = dist * 1.609344 } | |
if (unit=="N") { dist = dist * 0.8684 } | |
return dist | |
} | |
function load() { | |
lat = Number(document.getElementById('lat').value); | |
lon = Number(document.getElementById('lon').value); | |
console.log('File Changed'); | |
var files = window.event.target.files; // FileList object | |
var reader = new FileReader(); | |
// Closure to capture the file information. | |
reader.onload = function(e) { | |
console.log("Loaded"); | |
document.getElementById('list').innerHTML = 'Parsing file...'; | |
setTimeout(function(){ | |
var thing = JSON.parse(e.target.result); | |
console.log("Parsed"); | |
console.log(thing.locations[0]); | |
document.getElementById('list').innerHTML = 'Sorting locations by time...'; | |
setTimeout(function(){ | |
thing.locations.sort(function(a,b){ | |
return Number(a.timestampMs) - Number(b.timestampMs); | |
}); | |
console.log("Sorted"); | |
var output = []; | |
var matches = 0; | |
var lastTime = 0; | |
var totalTime = 0; | |
for (var i = 0; i < thing.locations.length; i++) { | |
var location = thing.locations[i]; | |
var d = distance(location.latitudeE7 / 1e7,location.longitudeE7 / 1e7,lat,lon); | |
var time = Number(location.timestampMs) | |
if(d < 0.1) { | |
totalTime += time - lastTime; | |
output.push('<li><strong style="width:30px; display:inline-block;">', matches++, '</strong> -- ', | |
d.toFixed(4), ' ~~ ', location.accuracy, ' == ', (totalTime / 3.6e+6), | |
'</li>'); | |
} else { | |
} | |
lastTime = time; | |
} | |
output.unshift('<li></li>'); | |
output.unshift('<li>Total Time: About ',(totalTime / 3.6e+6).toFixed(1),' hours</li>'); | |
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>'; | |
},0); | |
},0); | |
}; | |
// Read in the image file as a data URL. | |
document.getElementById('list').innerHTML = 'Reading file...'; | |
reader.readAsText(files[0]); | |
} | |
</script> | |
<input type="file" onChange="load()"> | |
<div id="list"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment