geolib - Geohash encoding and decoding

1.0.7 · active · verified Fri Apr 17

geolib is a Python library providing functionality for geohash encoding, decoding, and associated operations like bounding box calculation. It is currently at version 1.0.7 and has a relatively stable, infrequent release cadence, indicating a mature and well-defined feature set.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates encoding geographical coordinates into a geohash, decoding a geohash back to coordinates, and calculating the bounding box for a given geohash string.

from geolib import geohash

# Example: Encode latitude and longitude into a geohash string
latitude = 39.04
longitude = -77.48
precision = 9 # Desired geohash length

encoded_hash = geohash.encode(latitude, longitude, precision)
print(f"Encoded geohash for ({latitude}, {longitude}) with precision {precision}: {encoded_hash}")

# Example: Decode a geohash string back to latitude and longitude
decoded_lat, decoded_lon = geohash.decode(encoded_hash)
print(f"Decoded coordinates from {encoded_hash}: Latitude={decoded_lat}, Longitude={decoded_lon}")

# Example: Get the bounding box for a geohash
bbox_coords = geohash.bbox(encoded_hash)
print(f"Bounding box for {encoded_hash}: {bbox_coords}")

view raw JSON →