Show HN: Adaptive Geocodes – Truncatable Geocodes

1 day ago 3

The Adaptive Geocode (AGC) algorithm converts geographic coordinates (latitude/longitude) into a variable-length string and vice-versa. It operates on a rectilinear projection of the world (90°S to 90°N, 180°W to 180°E).

Encoding Process:

  1. Initial Grid: The world is first divided into an 8-column by 4-row grid (32 cells).
  2. Cell Identification: The cell containing the target coordinates is identified. Cells are indexed row by row, then column by column (0-31).
  3. First Character: The character from a predefined 36-character set (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) corresponding to this index (0-31) becomes the first character of the AGC.
  4. Recursive Subdivision: The identified cell then becomes the new bounding box for the next level of precision.
  5. Subsequent Grids: This new box is subdivided into a 6-column by 6-row grid (36 cells).
  6. Subsequent Characters: The character (from the same 36-character set) corresponding to the sub-cell containing the coordinates (indexed 0-35) is appended to the AGC.
  7. Iteration: Steps 4-6 are repeated until the desired code length (and thus precision) is achieved.

Decoding Process:

Decoding reverses this process. Each character in the AGC refines the bounding box based on the 8x4 grid for the first character and 6x6 grids for subsequent characters. The character's index within the ALPHABET determines which cell of the current grid to select as the new, smaller bounding box. This is repeated for all characters in the AGC.

The center of the final bounding box is typically used as the decoded coordinate pair.

Read Entire Article