Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Google Timeline Mileage

A small Python script that reads an exported Google Maps Timeline JSON file, finds your visits to a single destination, and writes a CSV of trips with mileage plus a monthly summary. Useful for reconstructing business mileage after the fact, when you forgot to track it and tax time is closing in.

There are no dependencies. It uses the Python standard library only.

Why this exists

Google moved Timeline to on-device-only storage in late 2024, so there is no web interface anymore and you cannot pull this up on your laptop. But your phone has quietly logged every place you visited and the driving distance of every trip. This script turns that export into an expense-report-ready CSV.

The full write-up is here: https://84em.com/blog/google-timeline-mileage-python-script/

Exporting your Timeline data (Android)

  1. Open your phone's Settings app
  2. Tap Location
  3. Tap Location services
  4. Tap Timeline
  5. Tap Export Timeline data
  6. Tap Continue
  7. Choose where to save the file (Google Drive, local storage, etc.)

The export is a single JSON file. As a reference point, a file covering data back to 2013 was about 79 MB.

Check these settings first

  • Auto-delete Timeline: set it to 36 months or Do not auto-delete. The default is 3 months, which permanently deletes older data. Google Maps profile, Your Timeline, three-dot menu, Location and privacy settings, Auto-delete Timeline.
  • Timeline Backup: turn cloud backup on so you do not lose the data if you switch phones. Google Maps profile, Your Timeline, cloud icon.

Usage

  1. Put the exported JSON next to timeline_mileage.py (or point TIMELINE_FILE at it).
  2. Open timeline_mileage.py and edit the CONFIG block at the top:
    • HOME_LAT / HOME_LNG and DEST_LAT / DEST_LNG. Find coordinates by searching the address on Google Maps and reading the numbers after the @ in the URL, for example .../@42.0163680,-91.6722428,17z.
    • START_DATE / END_DATE to limit the range, or leave them None.
    • MAX_TRIP_MILES to clamp outliers (see below), or leave it None.
  3. Run it:
python3 timeline_mileage.py

You get mileage_report.csv with one row per trip leg, a totals row, and a per-month summary printed to the terminal.

How it works

Timeline visits do not store street addresses. Each visit has a Google Place ID and a latitude/longitude pair. The script uses the haversine formula to match each visit's coordinates against your destination, within MATCH_RADIUS_METERS. For every match it reads the driving distance Google recorded on the adjacent activity segments, one for the trip there and one for the trip back.

The distance cap

Google's recorded distance is not always a clean point-A-to-point-B measurement. If you stopped for gas or took a detour, that mileage gets rolled into the activity segment, so a 2-mile route can show up as a 58-mile "return trip." Set MAX_TRIP_MILES to a reasonable maximum for your route and anything above it is clamped down. It is not forensically precise, but it is defensible and conservative, which is what you want for expense reporting. Leave it None to keep Google's raw numbers.

Privacy

Your Timeline.json and the generated *.csv contain detailed location history. Both are git-ignored in this repo so you cannot accidentally commit them. Do not share them.

License

MIT. See LICENSE.

About

Parse an exported Google Maps Timeline JSON file into a mileage CSV for expense reports

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages