Created
July 17, 2023 08:02
-
-
Save huntfx/fc9b9680388795b85f25b46e414ef62e to your computer and use it in GitHub Desktop.
Quick script to convert the Google Location History "Records.json" into a format compatible with kepler.gl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
# Open the JSON file and read its contents | |
print('Loading data...') | |
with open('Records.json') as json_file: | |
data = json.load(json_file) | |
# Create a CSV file and write the headers | |
print('Processing data...') | |
with open('Records.csv', 'w', newline='') as csv_file: | |
writer = csv.writer(csv_file) | |
writer.writerow(['timestamp', 'latitude', 'longitude']) | |
# Loop through each location in the JSON data and write it to the CSV file | |
for location in data['locations']: | |
timestamp = location['timestamp'] | |
try: | |
latitude = location['latitudeE7'] / 10**7 | |
longitude = location['longitudeE7'] / 10**7 | |
except KeyError: | |
continue | |
writer.writerow([timestamp, latitude, longitude]) | |
print('CSV file created') | |
input('Press enter to exit') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment