Recently I started using Obsidian and journaling daily. It took no time for me to start tracking all kinds of things for each day, and naturally some of those things ended up being my location and the weather.
It turns out that getting your accurate location in Obsidian is a bit of a pain in the ass. Most of the solutions I saw online were based on determining your location from your IP address which is, needless to say, wildly inaccurate. Others required you to run a separate (Android) app, or go through a web page
Now I wanted something that can requires minimum intervention on my part - I just
want things to work without me having to do any manual work.
Some caveats:
Anyway…
The gist of it is to create a Shortcut, which will run periodically (or on any other trigger you like) on a device that has location capabilities, and insert the location information directly in your vault, in a note, in FrontMatter
format. That’s pretty much it.
Here is a link to the shortcut if you want to directly use it. Just be sure to modify the path, as it will surely be different for your Vault. Just click on Meta
which will prompt you to point to a folder on your machine.
Or if you want to recreate it yourself, here’s a screenshot of the settings. Not sure if there’s a way to grab the raw code behind that shortcut, so far I haven’t found a way (but also haven’t looked much).
On my iphone I also have 2 automations that will run this shortcut:
Also I can trigger the shortcut manually whenever I want in order to update my location.
Then, using Templater
I can grab that information wherever I want, e.g. in my Daily notes and also get weather information based on my location.
<%-
async function getPageProperties(pageName) {
const dataviewApi = app.plugins.plugins.dataview.api;
const page = await dataviewApi.page(pageName);
return page;
}
const locationPage = await getPageProperties("600 - Other/Meta/location");
const city = locationPage.city;
const country = locationPage.country;
const latitude = locationPage.latitude;
const longitude = locationPage.longitude;
-%>
...
---
location: "<% latitude %>,<% longitude %>"
city: <% city %>, <% country %>
---
I use my phone as the source of my location, as it’s always on and I always have it with me. But you can also automate the Shortcut on a Mac.
You can do it through a calendar event, as described in the article. Or if you want you can also run it through cron
.
0 7 * * * shortcuts run "Obsidian Location"
Probably there are some other tools out there as well that can help you do that, but I haven’t really looked into them. I think either of those options should satisfy most use cases. The only caveat here is that your mac will have to be on for the scheduled event to work.