Skip to main content

Spying myself through the lense of Google Maps Timeline data


I took an export of my Google Maps Timeline data and discovered it to be a treasure trove of information. I was initially only interested in seeing how often I visit the local boulder gym, but I found myself soon digging into more such details.

The data consist of activities and place visits. An activity looks like this:

{
"activitySegment": {
"startLocation": {
"latitudeE7": 0,
"longitudeE7": 0,
"sourceInfo": {
"deviceTag": -0
}
},
"endLocation": {
"latitudeE7": 0,
"longitudeE7": 0,
"sourceInfo": {
"deviceTag": -0
}
},
"duration": {
"startTimestamp": "2023-02-01T03:49:39.393Z",
"endTimestamp": "2023-02-01T03:57:21.480Z"
},
"distance": 1110,
"activityType": "CYCLING",
"confidence": "HIGH",
"activities": [
{
"activityType": "CYCLING",
"probability": 89.22557234764099
},
{
"activityType": "WALKING",
"probability": 6.305336207151413
},
{
"activityType": "IN_PASSENGER_VEHICLE",
"probability": 1.5200317837297916
},
{
"activityType": "IN_BUS",
"probability": 1.4393270947039127
},
{
"activityType": "IN_SUBWAY",
"probability": 0.44777640141546726
},
{
"activityType": "MOTORCYCLING",
"probability": 0.3105701180174947
},
{
"activityType": "RUNNING",
"probability": 0.2760248025879264
},
{
"activityType": "IN_TRAIN",
"probability": 0.17639625584706664
},
{
"activityType": "IN_TRAM",
"probability": 0.15619536861777306
},
{
"activityType": "STILL",
"probability": 0.1334176049567759
},
{
"activityType": "IN_FERRY",
"probability": 0.0047270386858144775
},
{
"activityType": "SKIING",
"probability": 0.003990190816693939
},
{
"activityType": "SAILING",
"probability": 6.135768217063742e-4
},
{
"activityType": "FLYING",
"probability": 1.9939299988891435e-5
},
{
"activityType": "IN_VEHICLE",
"probability": 2.1501850647198673e-9
}
],
"waypointPath": {
"waypoints": [
{
"latE7": 0,
"lngE7": 0
},
{
"latE7": 0,
"lngE7": 0
},
{
"latE7": 0,
"lngE7": 0
}
],
"source": "INFERRED",
"roadSegment": [
{
"placeId": "someid",
"duration": "31s"
},
{
"placeId": "someid",
"duration": "16s"
},
{
"placeId": "someid",
"duration": "38s"
},
{
"placeId": "someid",
"duration": "28s"
},
{
"placeId": "someid",
"duration": "91s"
}
],
"distanceMeters": 1480.0706767917454,
"travelMode": "BICYCLE",
"confidence": 0.0
}
}
}

You can peek through the internals in a way since you can see which options for a given activity Google algorithms have considered.

A place visit, on the other hand, is:

{
"placeVisit": {
"location": {
"latitudeE7": 0,
"longitudeE7": 0,
"placeId": "ChIJC8gdEfd2jEYR-_H0G00KSq4",
"address": "Aninkaistenkatu, 20100 Turku, Suomi",
"name": "Linja-autoasema",
"semanticType": "TYPE_SEARCHED_ADDRESS",
"sourceInfo": {
"deviceTag": -0
},
"locationConfidence": 57.1172,
"calibratedProbability": 48.786476
},
"duration": {
"startTimestamp": "2023-01-01T03:37:21.480Z",
"endTimestamp": "2023-01-01T04:56:24.466Z"
},
"placeConfidence": "MEDIUM_CONFIDENCE",
"centerLatE7": 0,
"centerLngE7": 0,
"visitConfidence": 96,
"otherCandidateLocations": [{
"latitudeE7": 604571641,
"longitudeE7": 222681737,
"placeId": "ChIJc9Dc5Ph3jEYR8pWWIcfi0r4",
"address": "Läntinen Pitkäkatu 7, 20100 Turku, Suomi",
"name": "Turku Bus Station",
"locationConfidence": 13.238819,
"calibratedProbability": 11.307895
}, {
"latitudeE7": 604567433,
"longitudeE7": 222656352,
"placeId": "ChIJH7NECvd2jEYRH4YOsng8Ofw",
"address": "20100 Turku, Suomi",
"name": "Turku bus station",
"locationConfidence": 10.178642,
"calibratedProbability": 8.694055
}, {
"latitudeE7": 604564020,
"longitudeE7": 222666501,
"placeId": "ChIJPVBncfd2jEYRLLPS3XEXJ1I",
"address": "20100 Turku, Suomi",
"name": "Turku, bus station",
"locationConfidence": 9.436044,
"calibratedProbability": 8.059767
}],
"editConfirmationStatus": "NOT_CONFIRMED",
"locationConfidence": 46,
"placeVisitType": "SINGLE_PLACE",
"placeVisitImportance": "MAIN"
}
}
view raw placevisit.json hosted with ❤ by GitHub

As you can see, the data contains not just the place you can see from Maps you have visited but actually the metadata and the confidence scores of where Google thinks you have been.

Using the dataset, it is pretty easy to find out which locations you have visited and how long you have stayed. I co-authored with ChatGPT this simple script that outputs how many hours and times you have visited a given place.

import fs from 'fs'
import path from 'path';
// https://stackoverflow.com/questions/19700283/how-to-convert-time-in-milliseconds-to-hours-min-sec-format-in-javascript
function parseMillisecondsIntoReadableTime(milliseconds){
//Get hours from milliseconds
var hours = milliseconds / (1000*60*60);
var absoluteHours = Math.floor(hours);
var h = absoluteHours > 9 ? absoluteHours : '0' + absoluteHours;
//Get remainder from hours and convert to minutes
var minutes = (hours - absoluteHours) * 60;
var absoluteMinutes = Math.floor(minutes);
var m = absoluteMinutes > 9 ? absoluteMinutes : '0' + absoluteMinutes;
//Get remainder from minutes and convert to seconds
var seconds = (minutes - absoluteMinutes) * 60;
var absoluteSeconds = Math.floor(seconds);
var s = absoluteSeconds > 9 ? absoluteSeconds : '0' + absoluteSeconds;
return h + ':' + m + ':' + s;
}
let visits = 0;
let timeSpentMs = 0;
const placeNamePatterns = ['Interesting place', 'Interesting place with another name']
const dataDirPath = './data';
const yearsDirs = fs.readdirSync(dataDirPath);
yearsDirs.forEach((yearDir) => {
if (yearDir.length !== 4) {
return;
}
let visitsYear = 0;
let timeSpentYearMs = 0;
const yearDirPath = path.join(dataDirPath, yearDir);
const filesInYearDir = fs.readdirSync(yearDirPath);
filesInYearDir.forEach((filename) => {
const filePath = path.join(yearDirPath, filename);
const data = fs.readFileSync(filePath, 'utf8');
const timelineObjects = JSON.parse(data).timelineObjects;
for (const timelineObject of timelineObjects) {
if (timelineObject.placeVisit) {
const placeVisit = timelineObject.placeVisit.location.name;
const otherCandidateLocations = timelineObject.placeVisit.otherCandidateLocations;
if (placeNamePatterns.some((pattern) => placeVisit?.includes(pattern)) || otherCandidateLocations?.some((location) => placeNamePatterns.some((pattern) => location.name?.includes(pattern)))) {
const duration = timelineObject.placeVisit.duration;
const start = new Date(duration.startTimestamp);
const end = new Date(duration.endTimestamp);
timeSpentYearMs = timeSpentYearMs + (end - start);
visitsYear++;
}
}
}
});
visits = visits + visitsYear;
timeSpentMs = timeSpentMs + timeSpentYearMs;
if (visitsYear === 0) {
console.log(yearDir, 'no visits')
console.log('\n')
return;
}
console.log(yearDir)
console.log(visitsYear, 'visits')
console.log(parseMillisecondsIntoReadableTime(timeSpentYearMs), 'time spent')
const average = timeSpentYearMs / visitsYear;
console.log(parseMillisecondsIntoReadableTime(average), 'average time spent per visit')
console.log('\n')
});
console.log('Total')
console.log(visits, 'visits')
console.log(parseMillisecondsIntoReadableTime(timeSpentMs), 'time spent')
view raw timelinespy.js hosted with ❤ by GitHub

Comments

Popular posts from this blog

I'm not a passionate developer

A family friend of mine is an airlane pilot. A dream job for most, right? As a child, I certainly thought so. Now that I can have grown-up talks with him, I have discovered a more accurate description of his profession. He says that the truth about the job is that it is boring. To me, that is not that surprising. Airplanes are cool and all, but when you are in the middle of the Atlantic sitting next to the colleague you have been talking to past five years, how stimulating can that be? When he says the job is boring, it is not a bad kind of boring. It is a very specific boring. The "boring" you would want as a passenger. Uneventful.  Yet, he loves his job. According to him, an experienced pilot is most pleased when each and every tiny thing in the flight plan - goes according to plan. Passengers in the cabin of an expert pilot sit in the comfort of not even noticing who is flying. As someone employed in a field where being boring is not exactly in high demand, this sounds pro...

Canyon Precede:ON 7

I bought or technically leased a Canyon Precede:ON 7 (2022) electric bike last fall. This post is about my experiences with it after riding for about 2000 km this winter. The season was a bit colder than usual, and we had more snow than in years, so I properly put the bike through its paces. I've been cycling for almost 20 years. I've never owned a car nor used public transport regularly. I pedal all distances below 30km in all seasons. Besides commuting, I've mountain biked and raced BMX, and I still actively ride my road bike during the spring and summer months. I've owned a handful of bikes and kept them until their frames failed. Buying new bikes or gear has not been a major part of my hobby, and frankly, I'm quite sceptical about the benefits of updating bikes or gear frequently. I've never owned an E-bike before, but I've rented one a couple of times. The bike arrived in a hilariously large box. I suppose there's no need to worry about damage durin...

Emit structured Postgres data change events with wal2json

A common thing I see in an enterprise system is that when an end-user does some action, say add a user, the underlying web of subsystems adds the user to multiple databases in separate transactions. Each of these transactions may happen in varying order and, even worse, can fail, leaving the system in an inconsistent state. A better way could be to write the user data to some main database and then other subsystems like search indexes, pull/push the data to other interested parties, thus eliminating the need for multiple end-user originating boundary transactions. That's the theory part; how about a technical solution. The idea of this post came from the koodia pinnan alla podcast about event-driven systems and CDC . One of the discussion topics in the show is emitting events from Postgres transaction logs.  I built an utterly simple change emitter and reader using Postgres with the wal2json transaction decoding plugin and a custom go event parser. I'll stick to the boring ...