Geo

Geo / GeoHash / 0.1.1

README.md

0. TL; DR

This algorithm provides a unique identifier for a given coordinate.

1. Introduction

Geohash is a latitude/longitude geocode system invented by Gustavo Niemeyer when writing the web service at geohash.org, and put into the public domain. It is a hierarchical spatial data structure which subdivides space into buckets of grid shape, which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves.

Geohashes offer properties like arbitrary precision and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision).

As a consequence of the gradual precision degradation, nearby places will often (but not always) present similar prefixes. The longer a shared prefix is, the closer the two places are.

Input

  • (Required) Mode: Encode or Decode.
  • (Required) Latitude: Only required in encode mode.
  • (Required) Longitude: Only required in encode mode.
  • (Required) Geohash: Only required in decode mode.
  • (Optional) Precision: Precision point for encoding coordinates.

Output:

  • Geohash for encode mode.
  • Latitude and longitude for decode mode.

2. Example

Example 1.

  • Parameter 1: Mode (Encode)
  • Parameter 2: Latitude
  • Parameter 3: Longitude
{
    "mode": "encode",
    "latitude": 47.599240004249054,
    "longitude": -122.3333752155304
}

Output:

{
    "geohash": "c23nb1pt9v2n"
}

Example 2.

  • Parameter 1: Mode (Encode)
  • Parameter 2: Latitude
  • Parameter 3: Longitude
  • Parameter 4: Precision
{
    "mode": "encode",
    "latitude": 47.599240004249054,
    "longitude": -122.3333752155304,
    "precision": 6
}

Output:

{
    "geohash": "c23nb1"
}

Example 3.

  • Parameter 1: Mode (Decode)
  • Parameter 2: Geohash
{
    "mode": "decode",
    "geohash": "c23nb1pt9try"
}

Output:

{
  "latitude": 47.59923999197781,
  "longitude": -122.33337538316846
}