How to use location in org-roam?

I would like to be able to put, say, the latitude and longitude for a place into a node for that place, and then be able to find org-roam nodes that are within a specified distance from the first place.

For example, I make nodes for cities that have a person or company or institution I’m interested in. Take for argument’s sake, these nodes I really have:

:ID:       210914_155426
#+title: Palo Alto, CA


:ID:       210914_160652
#+title: Mountain View, CA

What if I added a LATLONG property like this: (I got the lat long from Wikipedia)

:ID:       210914_150202
:LATLONG: 37°22′16″N 122°2′15″W
#+title: Sunnyvale, CA

If I had the Mountain View node open in Emacs, I would like to be able to issue a command that would return all the nodes that are within say 10 miles of the lat long (I could put) in the Mountain View node.

I searched the discourse for proximity and location and didn’t find any conversation relevant to this.

I’m interested in this concept as well – very interesting use case.

From my understanding, this should be possible programmatically. This page has a good example as well as some code in different languages (no Lisp though).

I’d try to write something up in Lisp, but my primary coding language is C, so I’m probably not the best person to provide that.

I have done a quick experiment (code in Gist). It works on my end.

If someone can make it better, I’d love to see improvement. I just took it on as a technical exercise.

To use it:

  1. Evaluate all the functions in the Gist
  2. Create a couple of test nodes with a :geo: property
  3. Visit a Org-roam node that has a :geo: property – where you are will be the origin
  4. Run command my/list-node-IDs-within-range-of-distance
  5. Enter a number: that is the max distance in kilometers
  6. You will see a list of nodes ID that are within the kilometer distance

Please try not to be confused with the fact that the prompt asks for the max distance in kilometers and the resultant pop-up buffer shows the distance in meters. I could not show kilometers without rounding the values to 4km and 44km respectively (4 km vs 4.75 km is large enough for me to care).

Two notes:

  • I used GEO property name, not LATLONG but they denote the same thing
  • The value of GEO property must be decimal degrees and must be separated by a space
  • If you want to use this notation 37°22′16″N 122°2′15″W, you’d need to convert it
  • The algorithm is from this website – see the source code for a bit more detail

My test files are as follows.

File 1 (the origin)

:modified: 2023-07-30T182055
:ID:       2023-07-30T163232
:geo: 37.3927 -122.042
#+title: test GEO Mountain View
#+filetags: test

File 2

:modified: 2023-07-30T164943
:ID:       2023-07-30T164720
:geo: 37.3587 -122.075
#+title: test GEO 10km Ortega park

File 3

:modified: 2023-07-30T165100
:ID:       2023-07-30T165039
:geo: 37.0154 -122.211
#+title: test GEO more than 10km Devon Port
#+filetags: test