• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
anand_g

anand_g

Geohash

Public
Like
Geohash
Home
Code
3
frontend
2
README.md
H
geohash.ts
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
geohash.ts
https://anand_g--b717c31c3d7c11f0a60c76b3cceeab13.web.val.run
README.md

Geohash Converter

A Val Town service that converts latitude and longitude coordinates to geohash with configurable precision. Features both a user-friendly web interface and a REST API.

🌐 Web Interface

Visit the root URL to access the interactive web interface with:

  • Easy-to-use form with latitude, longitude, and precision inputs
  • 5 sample locations you can click to auto-fill the form:
    • 🗽 New York City (40.7128, -74.0060)
    • 🌉 San Francisco (37.7749, -122.4194)
    • 🏰 London (51.5074, -0.1278)
    • 🗼 Tokyo (35.6762, 139.6503)
    • 🏄 Sydney (-33.8688, 151.2093)
    • 🗼 Paris (48.8566, 2.3522)
  • Real-time conversion with beautiful results display
  • Copy-to-clipboard functionality for generated geohashes
  • Responsive design that works on desktop and mobile

🚀 API Features

  • Convert lat/lng coordinates to geohash
  • Configurable precision (1-12 characters)
  • Returns bounding box for the generated geohash
  • Supports both GET and POST requests
  • Input validation and error handling

API Usage

GET Request

GET /geohash?lat=40.7128&lng=-74.0060&precision=8

Parameters:

  • lat (required): Latitude (-90 to 90)
  • lng (required): Longitude (-180 to 180)
  • precision (optional): Geohash precision (1-12, default: 8)

POST Request

POST /geohash
Content-Type: application/json

{
  "lat": 40.7128,
  "lng": -74.0060,
  "precision": 8
}

Response Format

{ "geohash": "dr5regw3", "lat": 40.7128, "lng": -74.006, "precision": 8, "bbox": { "minLat": 40.7127571105957, "maxLat": 40.712928771972656, "minLng": -74.00630950927734, "maxLng": -74.00596618652344 } }

Precision Levels

Geohash precision determines the accuracy of the location:

PrecisionLat ErrorLng ErrorApprox. Size
1±23°±23°5,000km
2±2.8°±5.6°1,250km
3±0.70°±0.70°156km
4±0.087°±0.18°39km
5±0.022°±0.022°4.9km
6±0.0027°±0.0055°1.2km
7±0.00068°±0.00068°153m
8±0.000085°±0.00017°38m
9±0.000021°±0.000021°4.8m
10±0.0000027°±0.0000054°1.2m
11±0.00000067°±0.00000067°149mm
12±0.000000084°±0.00000017°37mm

Examples

New York City (Manhattan)

curl "https://your-val.web.val.run/geohash?lat=40.7128&lng=-74.0060&precision=8" # Returns: "dr5regw3"

San Francisco

curl -X POST "https://your-val.web.val.run/geohash" \ -H "Content-Type: application/json" \ -d '{"lat": 37.7749, "lng": -122.4194, "precision": 10}' # Returns: "9q8yyk8ytp"

London

curl "https://your-val.web.val.run/geohash?lat=51.5074&lng=-0.1278&precision=6" # Returns: "gcpuvp"

Error Handling

The API returns appropriate HTTP status codes and error messages:

  • 400 Bad Request: Invalid parameters or missing required fields
  • 405 Method Not Allowed: Unsupported HTTP method

Example error response:

{ "error": "Invalid request", "message": "Latitude must be a number between -90 and 90" }

What is Geohash?

Geohash is a geocoding system that represents geographic coordinates as a short alphanumeric string. It has several useful properties:

  • Hierarchical: Longer geohashes are more precise
  • Proximity: Similar geohashes are geographically close
  • Compact: Efficient string representation of coordinates
  • Base32: Uses characters 0-9 and b-z (excluding a, i, l, o)

Implementation Details

This implementation uses the standard geohash algorithm:

  1. Interleaves longitude and latitude bits
  2. Encodes using base32 character set
  3. Provides bounding box calculation for reverse lookup
  4. Validates input coordinates and precision values
HTTP
  • geohash.ts
    anand_g--b717c31c3d7c11f0a60c76b3cceeab13.web.val.run
Code
frontendREADME.md
H
geohash.ts
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.