Geohash2

1.1 · maintenance · verified Sun Apr 12

Geohash2 is a Python module providing functions to encode and decode geographic coordinates (latitude and longitude) into Geohash strings and vice-versa. It is a Python 3-compatible fork of the original 'geohash' library, initially released in July 2017. The library appears to be in maintenance mode with no recent updates, but remains functional for its core purpose.

Warnings

Install

Imports

Quickstart

Demonstrates encoding latitude and longitude into geohash strings, including specifying precision. Also shows decoding a geohash back into coordinates, with options for approximate string output or exact float output with error margins.

import geohash2

# Encode coordinates to a geohash
latitude = 42.6
longitude = -5.6
geohash_code = geohash2.encode(latitude, longitude)
print(f"Geohash for {latitude}, {longitude}: {geohash_code}")

# Encode with specified precision
geohash_precision_5 = geohash2.encode(latitude, longitude, precision=5)
print(f"Geohash (precision 5) for {latitude}, {longitude}: {geohash_precision_5}")

# Decode a geohash to coordinates (returns strings)
decoded_coords_str = geohash2.decode('ezs42')
print(f"Coordinate for Geohash ezs42: {decoded_coords_str}")

# Decode a geohash exactly (returns floats with error margins)
decoded_exact_coords = geohash2.decode_exactly('ezs42')
print(f"Exact coordinate for Geohash ezs42: {decoded_exact_coords}")

view raw JSON →