{"id":4546,"library":"geohash2","title":"Geohash2","description":"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.","status":"maintenance","version":"1.1","language":"en","source_language":"en","source_url":"https://github.com/dbarthe/geohash/","tags":["geohash","gis","geolocation","encoding","decoding","latitude","longitude","python3"],"install":[{"cmd":"pip install geohash2","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Function to encode latitude and longitude into a geohash string.","symbol":"encode","correct":"from geohash2 import encode"},{"note":"Function to decode a geohash string into a (latitude, longitude) tuple of strings.","symbol":"decode","correct":"from geohash2 import decode"},{"note":"Function to decode a geohash string into an exact (latitude, longitude, lat_error, lon_error) tuple of floats.","symbol":"decode_exactly","correct":"from geohash2 import decode_exactly"}],"quickstart":{"code":"import geohash2\n\n# Encode coordinates to a geohash\nlatitude = 42.6\nlongitude = -5.6\ngeohash_code = geohash2.encode(latitude, longitude)\nprint(f\"Geohash for {latitude}, {longitude}: {geohash_code}\")\n\n# Encode with specified precision\ngeohash_precision_5 = geohash2.encode(latitude, longitude, precision=5)\nprint(f\"Geohash (precision 5) for {latitude}, {longitude}: {geohash_precision_5}\")\n\n# Decode a geohash to coordinates (returns strings)\ndecoded_coords_str = geohash2.decode('ezs42')\nprint(f\"Coordinate for Geohash ezs42: {decoded_coords_str}\")\n\n# Decode a geohash exactly (returns floats with error margins)\ndecoded_exact_coords = geohash2.decode_exactly('ezs42')\nprint(f\"Exact coordinate for Geohash ezs42: {decoded_exact_coords}\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure you are installing 'geohash2' and using `import geohash2` or `from geohash2 import ...` instead of the older 'geohash' package and its import patterns.","message":"This 'geohash2' package specifically addresses Python 3 compatibility issues found in the original 'geohash' library. If migrating from the original 'geohash' (version 1.0 or older), direct `import geohash` statements might fail due to Python 3 syntax differences.","severity":"breaking","affected_versions":"N/A (issue with original 'geohash' package, 'geohash2' fixes it)"},{"fix":"Use `float(latitude_str)` and `float(longitude_str)` for numeric calculations after using `decode()`, or use `decode_exactly()` if float output and error margins are needed directly.","message":"The `decode()` function returns latitude and longitude as strings, which may require explicit type conversion (e.g., `float()`) for mathematical operations. The `decode_exactly()` function returns floats, along with latitude and longitude error margins.","severity":"gotcha","affected_versions":"1.1"},{"fix":"When performing proximity searches or calculating distances, do not solely rely on geohash prefix matching for edge cases. Consider using more robust spatial indexing methods or calculating actual distances (e.g., Haversine formula) for nearby points.","message":"Geohashes do not guarantee spatial proximity based on common prefixes across certain boundaries (e.g., the 180-degree meridian, the Equator, or poles). Locations very close physically might have entirely different geohash prefixes due to how the grid is subdivided.","severity":"gotcha","affected_versions":"All (inherent to Geohash algorithm)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}