Skip to content

Instantly share code, notes, and snippets.

@gyng
Last active March 6, 2024 14:02
Show Gist options
  • Save gyng/e0f7eac4445793ef3b4d59ca0b0fa6b4 to your computer and use it in GitHub Desktop.
Save gyng/e0f7eac4445793ef3b4d59ca0b0fa6b4 to your computer and use it in GitHub Desktop.
Get Google Maps Location History manually from the browser

Get Google Maps Location History manually from the browser

  1. Modify startDate and endDate
  2. Paste this into your browser while logged in to Google
  3. Manually open each URL in the browser: it should download the KML for the day

Notes

  • Google's API only returns a maximum of one day's of data

  • You have to merge the resulting KML yourself

  • You might want this because

    • Google Takeout is not triggering scheduled takeout exports
    • Google Takeout takes a few days after scheduling to run the export
    • Google Takeout exports JSON

    This is working as of Feb 2024. There is no guarantee this will continue working in future.

function makeUrlForDate(year, month, day) {
// month is 0-indexed ie, Jan = 0
// Google only returns one day's worth of data even if more is requested
return `https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i${year}!2i${month}!3i${day}!2m3!1i${year}!2i${month}!3i${day}`;
}
var getDaysArray = function (start, end) {
for (
var arr = [], dt = new Date(start);
dt <= new Date(end);
dt.setDate(dt.getDate() + 1)
) {
arr.push(new Date(dt));
}
return arr;
};
const startDate = new Date("2024-02-10");
const endDate = new Date("2024-02-27");
const dates = getDaysArray(startDate, endDate);
const urls = dates
.map((date) => {
// getMonth is 0-indexed
return makeUrlForDate(date.getFullYear(), date.getMonth(), date.getDate());
})
.reduce((acc, val) => {
return acc.concat(val);
}, []);
console.log(urls);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment