Skip to content

Instantly share code, notes, and snippets.

@devdattaT
Last active October 26, 2024 19:51
Show Gist options
  • Save devdattaT/018f7fc153d9a82d83775351576965f3 to your computer and use it in GitHub Desktop.
Save devdattaT/018f7fc153d9a82d83775351576965f3 to your computer and use it in GitHub Desktop.
How to Visualize your Google Location History

Google is extremely transparent about the Location History it has on you. You can check it out on the timeline feature in the Google Maps application on the phone, or on https://www.google.com/maps/timeline It is possible that you have that turned off, and in that case, consider yourself lucky.

If there is data there, you can view it online, or Download and Analyze it yourself.

Note: The conversion script has been updated on 2024-06-24, to match the updated format which is now generated by Google Takeout

@dimisjim
Copy link

dimisjim commented Jun 9, 2024

This is what worked for me: https://gist.github.com/dimisjim/173c78d01219bc767d1f373e48e6a28a

Used latest a month's JSON google takeaway dump from 2024, and then loaded into kepler.gl, which actually worked and showed the points on the map correctly. However I couldn't draw any lines between them properly.

@ceemjay
Copy link

ceemjay commented Jun 23, 2024

Which file does this process? I have tried Records.json which returns a blank file and also one of the monthly files below Semantic Location History.. The latter prints records to the screen ending with
[datetime.datetime(2013, 7, 31, 18, 37, 0, 689000), '2013-07-31', '18:37:00', datetime.datetime(2013, 8, 1, 7, 5, 31, 822000), '2013-08-01', '07:05:31', -1.5501967, 47.2090939, 'CueZO6d0gRwhIJA1y_T-raagsZM', 'An address record', 73.671555, 'N/A', 'N/A']
Traceback (most recent call last):
File "/home/clive/to.py", line 113, in
for r in reader:
File "/home/clive/to.py", line 58, in make_reader
activity_type = segment['activityType']
KeyError: 'activityType'

Thanks

@devdattaT
Copy link
Author

@ceemjay This process has to be run with the Records.json.
I realised that the file generated by Google Takeout, has been updated, and I have updated the conversion script accordingly.

@GitMae99
Copy link

Once I switched to timeline on my device, Google Takeout doesn't export any relevant Timeline data for me. No Records.json. You guys are awesome trying to keep up with Google's latest fiasco. Will continue following your progress. Thank You!

@usbrpa
Copy link

usbrpa commented Jul 1, 2024

Not sure if I am doing this right,.. but I had the same issues with the timeline... need to be able to retrace my travels over the past weeks / months. So I tried something: https://github.com/usbrpa/timeline2map Feel free to have a look.

@lsschlieper
Copy link

Not sure if I am doing this right,.. but I had the same issues with the timeline... need to be able to retrace my travels over the past weeks / months. So I tried something: https://github.com/usbrpa/timeline2map Feel free to have a look.

just logged in to say this worked for me. Had to pull out all my timeline history for a court apeal and this tool did the trick. Thanks

@dimisjim
Copy link

Indeed, https://github.com/usbrpa/timeline2map works pretty nicely. thanks @usbrpa

It uses the export straight from your android device settings, rather than the one exported via google itself

@anselm
Copy link

anselm commented Sep 20, 2024

It's easier to ask chatgpt to generate a view that directly reads the json into a map:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Location Path Map</title>
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
    <style>
        #map {
            height: 600px;
            width: 100%;
        }
    </style>
</head>
<body>
    <h1>Location Path Map</h1>
    <div id="map"></div>

    <script>
        // Initialize the map and set its view to a default location (centered on the world)
        const map = L.map('map').setView([0, 0], 2);

        // Add OpenStreetMap tile layer
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);


        // Fetch location-history.json file
        fetch('location-history.json')
            .then(response => response.json())
            .then(data => {
                // Process each item in the data
                data.forEach(item => {
                    if (item.timelinePath) {
                        console.log("fetching",item)
                        const pathPoints = [];
                        item.timelinePath.forEach(point => {
                            // Split the "geo:" coordinates
                            const [lat, lon] = point.point.replace('geo:', '').split(',');

                            // Add the lat/lon as Leaflet LatLng objects to pathPoints
                            pathPoints.push([parseFloat(lat), parseFloat(lon)]);
                        });

                        // Draw a polyline for each timelinePath
                        const polyline = L.polyline(pathPoints, { color: 'blue' }).addTo(map);
                    }

                });

            })
            .catch(error => console.error('Error fetching location-history.json:', error));
    </script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment