[Feature Request] use Geolocation API
Kageetai opened this issue · 4 comments
Hey there,
really like your plugin, perfectly complements my journal writing :)
Just one idea, would it be possible to use the Geolocation API to fetch the current location instead of prompting the user? Maybe with another command?!
Thanks! I'm glad to hear it's helping at least one other person.
I like the idea of your feature request, but I don't know if the specific API will work. On my MacBook, calling it from the console gives me a permission error without actually prompting me for permission, and I'd suspect that Obsidian's Electron build doesn't have it enabled at all. I also don't think it would work on mobile, which isn't necessarily a deal-breaker but isn't ideal, either.
We could use an IP geolocation API like https://ip-api.com/, but that's so broad that the results may not be super useful, especially in dense areas like cities. That would be pretty simple and work cross-platform, though, so it's tempting.
I'll play around with this and see if there's any way of getting the geolocation API to work, and if not I'll prototype something IP-based and see how that works.
Ah, too bad, I also just tried it, and got the same. I guess it has to do with some configuration of Election of Obsidian. I am not familiar with those.
Your other idea sounds interesting too, but would probably be too broad as you already said. Also i am usually behind a VPN, which would further distort the results... :/
I looked into this a bit more and was able to give Obsidian location permissions, but I just got a different error about API permissions. In fact, Electron is pretty specific about how the API has to be configured (it's specifically tied to the Google Cloud Platform geolocation service): https://github.com/electron/electron/blob/main/docs/api/environment-variables.md#google_api_key
There's an open feature request on the Obsidian forums about the API in question. In a perfect world, users would be able to provide their own API keys, but as far as I can tell it has to be configured at build time, so I doubt the Obsidian folks would be interested in setting this up and paying for all API requests, too.
As for the IP approach, it was indeed quite easy to wire up but is too broad to be useful, I think. In NYC it doesn't even reliably return the right city, so anything more fine-grained like latitude and longitude is completely off.
I'm happy to keep this issue open in case anyone has a better approach, since I do think it would be a useful feature, but I don't know if we'll be able to do anything without some level of buy-in from Obsidian core.
Hmm, interesting, and a bit weird that Electron requires the Google Cloud Platform to use this relatively standard browser API, but it sounds like it's an Android restriction from Google. Damn...
And if it's like this, then even Obsidian core can't do much about it...
The IP approach doesn't sound worthwhile to me then either.
Thanks for looking into it.