esm7 / obsidian-map-view

Interactive map view for Obsidian.md
MIT License
546 stars 25 forks source link

FR: Ability to import lists from google maps #203

Open Caotenhoch2 opened 9 months ago

Caotenhoch2 commented 9 months ago

I would love to have a feature with which one could import previously in google maps created lists. Probably the easiest way would be for the user to upload their list csv file exported using takeout.google.com. This file is formatted in a way which should make it quite easy to import to the map/notes: Name of the place + ",," + the google.com/maps/place/ link + "," at the end of the line.

When importing this file, a folder with all notes could be created. The name of the note would be the name of the place and the only content of the note could be the geo: link to the place.

This feature would greatly improve changing to the plugin, as it no longer takes an eternity to transfer a list from google to the plugin/obsidian.

Caotenhoch2 commented 9 months ago

Something like this should do the job, but I don't know how to implement it with obsidian in mind

import * as fs from 'fs';

function read(): void {
    /** Reads the file exported from google as lines */
    const input: string = 'input.csv';
    const lines: string[] = fs.readFileSync(input, 'utf-8').split('\n');
    lines.shift();

    /** Iterates trough valid lines (not null or empty and includes ",,") */
    for (const s of lines) {
        if (s && !s.trim().isEmpty() && s.includes(',,')) {
            const split: string[] = s.substring(0, s.length - 1).split(',,');
        /** Prints the file out with the place as the filename and the link to the place as their content */
            const file: string = `out/${split[0]}`;
            fs.writeFileSync(file, split[1]);
        }
    }
}
esm7 commented 9 months ago

That's a nice idea. Some time ago I made an experimental import tool in Map View, it is basically still there, and can in theory import KML files generated from Google Maps lists. (I don't recall how, but I managed to export a list to a KML file.) It's unmaintained, and probably broken, but if Takeout uses a CSV file it will probably be even easier.

ngracilla commented 9 months ago

I've been doing some research on this. Takeout provides Google Map Places Lists in a csv format, but does not include lat/lon in the URL. It looks like:

https://www.google.com/maps/place/Mozzabella+Mercato+delle+Erbe/data=!4m2!3m1!1s0x477fd49401b1db2d:0xfd56772956968f68

I learned the last part of the data pairing is hex for a Customer ID object, likely from Google's Places API. The URL does resolve to one with lat/lon, though.

See https://stackoverflow.com/questions/47017387/decoding-the-google-maps-embedded-parameters and https://stackoverflow.com/questions/18413193/how-do-i-decode-encode-the-url-parameters-for-the-new-google-maps/34275131#34275131 for details.

aubreyz commented 9 months ago

There are plenty of tools, even online ones, to convert KML files to csv, eg. https://mygeodata.cloud/converter/kml-to-csv

There is also this obsidian plugin which imports csv files to pages https://github.com/farling42/obsidian-import-json which will create json fields from that csv too (not tried by me)

But I think a discussed and developed method would be more useful than trying to shoehorn this into the present plugin

architaktus commented 9 months ago

I wrote a simple tool to convert the KML of google earth to .md files for myself. Maybe it could help a bit

https://github.com/architaktus/kml-to-obsidian-markdown

esm7 commented 7 months ago

Sorry for the late reply. This is super useful and I'd love to integrate that. As soon as I find some time for plugins development & maintenance (maybe in the upcoming weeks), I'll prioritize this. Thank you!