Geohash
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.
geohash.ts
https://anand_g--b717c31c3d7c11f0a60c76b3cceeab13.web.val.run
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.
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
- 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
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 /geohash
Content-Type: application/json
{
"lat": 40.7128,
"lng": -74.0060,
"precision": 8
}
{ "geohash": "dr5regw3", "lat": 40.7128, "lng": -74.006, "precision": 8, "bbox": { "minLat": 40.7127571105957, "maxLat": 40.712928771972656, "minLng": -74.00630950927734, "maxLng": -74.00596618652344 } }
Geohash precision determines the accuracy of the location:
Precision | Lat Error | Lng Error | Approx. 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 |
curl "https://your-val.web.val.run/geohash?lat=40.7128&lng=-74.0060&precision=8" # Returns: "dr5regw3"
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"
curl "https://your-val.web.val.run/geohash?lat=51.5074&lng=-0.1278&precision=6" # Returns: "gcpuvp"
The API returns appropriate HTTP status codes and error messages:
400 Bad Request
: Invalid parameters or missing required fields405 Method Not Allowed
: Unsupported HTTP method
Example error response:
{ "error": "Invalid request", "message": "Latitude must be a number between -90 and 90" }
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)
This implementation uses the standard geohash algorithm:
- Interleaves longitude and latitude bits
- Encodes using base32 character set
- Provides bounding box calculation for reverse lookup
- Validates input coordinates and precision values