Skip to content

Instantly share code, notes, and snippets.

@alexhanh
Created March 1, 2015 18:58
Show Gist options
  • Save alexhanh/65b16b1c9966a73dd82f to your computer and use it in GitHub Desktop.
Save alexhanh/65b16b1c9966a73dd82f to your computer and use it in GitHub Desktop.
Analyzing Google location data https://maps.google.com/locationhistory/b/0
require 'haversine'
require 'json'
require 'time'
require 'date'
data = JSON.parse(File.read('LocationHistory.json'))
jyvaskyla = [62.244747, 25.7472184]
away_days = {}
data['locations'].reverse.each do |location|
time = Time.at(location['timestampMs'].to_i / 1e3)
lat = location['latitudeE7'] / 1e7
lon = location['longitudeE7'] / 1e7
pos = [lat, lon]
if Haversine.distance(pos, jyvaskyla).to_kilometers > 100.0 && time.year == 2014
away_days[time.to_date] = true
end
end
puts away_days.keys.count
@alexhanh
Copy link
Author

alexhanh commented Mar 1, 2015

Note: Get the JSON data from https://www.google.com/settings/takeout (choose only Location History)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment