License: Apache 2.0

How Bgrid Works

The Core Concept

BGrid transforms continuous geographic coordinates (Latitude, Longitude) into a discrete, hierarchical address.

Instead of arbitrary numbers, we use the BIP39 wordlist (2048 words) to encode location. This means every “cell” in our grid is identified by a single word.

To address the entire world with precision, we nest these grids.

Level 1: The Global Grid

The world is projected onto a 2D plane (x,yx, y normalized to [0,1][0, 1]). We divide this plane into 2048 cells.

Ncells=64×32=2048N_{cells} = 64 \times 32 = 2048

Why 64×3264 \times 32? The Earth is twice as wide (360° Longitude) as it is tall (180° Latitude). By using twice as many columns as rows, each cell remains roughly square near the equator.

Level 2: Refinement

Inside each Level 1 cell, we divide again by 2048. However, to maintain aspect ratio and precision, we swap the dimensions:

Level2:32×64=2048Level 2: 32 \times 64 = 2048

This alternating strategy ensures that errors don’t accumulate in one dimension.

The Algorithm

Given a coordinate (lat,lon)(lat, lon):

  1. Normalize:

    x=lon+180360,y=90lat180x = \frac{lon + 180}{360}, \quad y = \frac{90 - lat}{180}
  2. Iterate (for each level LL):

    • Determine dividers:

      • If LL is odd: dx=64,dy=32d_x = 64, d_y = 32
      • If LL is even: dx=32,dy=64d_x = 32, d_y = 64
    • Calculate Cell Column and Row:

      col=x×dxcol = \lfloor x \times d_x \rfloor row=y×dyrow = \lfloor y \times d_y \rfloor
    • Calculate Index (1-2048):

      index=(row×dx)+col+1index = (row \times d_x) + col + 1
    • Zoom in (update x,yx, y to be relative to current cell):

      x=(x×dx)colx = (x \times d_x) - col y=(y×dy)rowy = (y \times d_y) - row

This process repeats until the desired precision is reached.

  • Level 4 gives accuracy within meters (comparable to GPS for navigation).

Why BIP39?

The BIP39 standard defines a list of 2048 distinct, memorable words. It was designed for Bitcoin seed phrases, but it’s perfect for coordinates because:

  1. Error Correction: Words are chosen to be distinct (first 4 letters are unique).
  2. Global Support: Wordlists exist for English, Spanish, French, Chinese, etc.
  3. Human Friendly: “Apple” is easier to remember than “10010011”.