Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrienjoly/21e60637d536fdb790a34198449c377d to your computer and use it in GitHub Desktop.
Save adrienjoly/21e60637d536fdb790a34198449c377d to your computer and use it in GitHub Desktop.
Select date/time range from Google Location History JSON, using jq
#!/usr/bin/env bash
# First, download "Location History" from https://takeout.google.com/settings/takeout?hl=en&gl=EN&expflags
# (fr: "Historique des positions" from https://takeout.google.com/settings/takeout?hl=fr&gl=FR&expflags)
#
# => Big "Location history.json" file that looks like that:
#
# {
# "locations": [
# { "timestampMs": "1546415889121" },
# { "timestampMs": "1546415725521" }
# ]
# }
#
# Then, pick your date/time range:
#
START_TIME='2019-01-01T1:00:00Z'
END_TIME='2019-01-03T1:00:00Z'
#
# And generate a JSON file that only returns the location history for that range:
#
cat "Location History.json" | jq --arg s ${START_TIME} --arg e ${END_TIME} '
[($s, $e) | fromdate] as $r |
[ .locations[] |
select(
(.timestampMs|tonumber) >= ($r[0] * 1000) and
(.timestampMs|tonumber) <= ($r[1] * 1000)
)
]' > filtered-location-history.json
#
# Convert it to a simpler "journey" format:
#
cat "filtered-location-history.json" | jq '[ .[] | {
timestamp: .timestampMs|tonumber,
lat: (.latitudeE7 / 10000000),
lng: (.longitudeE7 / 10000000)
} ]' > journey.json
#
# (you may require: $ brew install jq)
#
# Then, you can use that file to render your replay your journey on a map
# --> https://github.com/sebastianvirlan/maps-journey-replay/issues/1
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment