Add current GPS coordinates to frontmatter with Space Script

I’m still new to SilverBullet and still trying it out, but one of my main use cases for any note app is to create “quick” notes from my phone. In these notes, I like having extra metadata like the gps location of my phone when I created the note.

After some experimenting with the new Space Script functionality, it was suprisingly easy to add what I wanted!

In a new note, I added this space script

silverbullet.registerFunction("getGpsCoords", () => {
  return new Promise((resolve, reject) => {
    navigator.geolocation.getCurrentPosition((position) => {
      const latitude = position.coords.latitude;
      const longitude = position.coords.longitude;
      syscall("editor.flashNotification", `GPS: ${latitude}, ${longitude}`);
      resolve(`${latitude}, ${longitude}`);
    }, (error) => {
      console.log('Geolocation error:', error);

And then in the default Quick Note template (imported from the Core library), I changed the frontmatter to use this new function:

description: "Create a quick note"
tags: template
  suggestedName: "Inbox/{{today}} {{time}}"
  confirmName: false
  command: "Quick Note"
  key: "Alt-Shift-n"
  dateCreated: "{{today}}"
  gps: "{{getGpsCoords}}"

Now whenever I create a new note using this template, I automatically get a gps frontmatter key with my current coordinates.

Note: You have to allow your browser to access your location for this to work. Also I noticed sometimes the function gets called twice. I’m not really sure why yet, but it does cause a delay when creating new notes.


This is very interesting, thanks for sharing. I’ll test it as soon as I update my Docker image. Currently is not supporting the space script thingy :smiley:

1 Like