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.
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/
- Open your phone's Settings app
- Tap Location
- Tap Location services
- Tap Timeline
- Tap Export Timeline data
- Tap Continue
- 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.
- 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.
- Put the exported JSON next to
timeline_mileage.py(or pointTIMELINE_FILEat it). - Open
timeline_mileage.pyand edit the CONFIG block at the top:HOME_LAT/HOME_LNGandDEST_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_DATEto limit the range, or leave themNone.MAX_TRIP_MILESto clamp outliers (see below), or leave itNone.
- Run it:
python3 timeline_mileage.pyYou get mileage_report.csv with one row per trip leg, a totals row, and a per-month summary printed to the terminal.
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.
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.
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.
MIT. See LICENSE.