Count number of days at location based on Google Maps Timeline data
More than once I was interested in the number of unique days I was at a certain location, based on my location data tracked by the Google Maps Timeline feature. Google Maps exposes some summary-like data, but not for all locations and not for exact time-frames.
I need this most frequently to count the number of unique days I was at my work location in a given calendar year, to correctly calculate both the commuting allowance and home-office allowance for the German income tax declaration.
I got a reliable count of unique days by exporting the raw Google Maps Timeline data and running a Python script on it that checks for all visits tracked if they are within a configurable range of a configurable location The script then returns both the days and times you were at (or near to) the location, as well as the total count of unique days.
-
Export the raw timeline data.
From an Android device you can get to the raw data by going to the Android settings, navigating to "Location", "Location Services", "Timeline", and then clicking on "Export timeline data". This will give you a JSON-file that you can save on your phone.
-
Transfer the raw timeline data to whichever device you'll run the Python script from.
-
Save the following Python script:
# --- Modify the values in this section to fit your purpose --- = = = 100 = = = # ------------------------------------------------------------- """ See <https://en.wikipedia.org/wiki/Haversine_formula> for more information. """ = 6_371_000 = = = = = = 2 * = * return = , = = return , = = continue = = continue continue = ,
-
Modify the variables defined in the Python script to fit your needs:
-
TIMELINE_JSON_PATH
: set this to where the script can find the raw Google Maps Timeline export. -
TARGET_LOCATION
: set this to the latitude and longitude of the location you want to count visits for.You can get this most easily by opening Google Maps and going to the location in question. A right-click opens a context menu where the top-most item should be the coordinates, which you can click to add them to your clipboard.
-
RANGE_TO_LOCATION_IN_METERS
: set this to the radius in meters within which you should be considered to have visited the location. -
LOCAL_TIMEZONE
: set this to your local timezone. -
LOWER_BOUND
: this is the inclusive lower bound from when on a visit will be counted. -
UPPER_BOUND
: this is the exclusive upper bound from when on a visit will no longer be counted.
-
-
Run the script.
You need at least Python version 3.9 to run it.