Geohash Area Utilities

0.1.0 · active · verified Wed Apr 22

The `geohash-area` library provides specialized utilities for working with geohashes, primarily focused on generating and querying geohashes for rectangular regions and arbitrary areas. It is designed to facilitate efficient spatial lookups in databases by producing a set of geohashes that cover a specific geographical extent. The package is currently at version 0.1.0, indicating an early development stage, and while a specific release cadence is not defined, its focused scope suggests a stable, yet evolving, set of core functionalities. Key differentiators include its unique `rect` function for radial geohash generation and an `area` function that supports recursively determining geohashes for complex, user-defined geographical boundaries via a callback, setting it apart from more generic geohash encoding/decoding libraries. It ships with comprehensive TypeScript type definitions, ensuring a robust development experience.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates encoding, decoding, generating geohashes for a rectangular area, and calculating distance between two points using the `geohash-area` library.

import * as geohash from 'geohash-area';

// 1. Encode a point to a geohash
const lat = 34.0522;
const lng = -118.2437;
const precision = 6;
const encodedHash = geohash.encode(lat, lng, precision);
console.log(`Encoded Geohash for (${lat}, ${lng}) with precision ${precision}: ${encodedHash}`);

// 2. Decode a geohash to its bounding box and midpoint
const decodedInfo = geohash.decode(encodedHash);
console.log('Decoded Geohash info:', decodedInfo);

// 3. Generate geohashes for a rectangular area around a point
const distanceMiles = 5;
const areaHashes = geohash.rect(lat, lng, distanceMiles, precision);
console.log(`Geohashes covering a ${distanceMiles}-mile radius around (${lat}, ${lng}):`, areaHashes.slice(0, 5), `... (${areaHashes.length} total)`);

// 4. Calculate distance between two points (in miles)
const point1 = { lat: 34.0522, lng: -118.2437 };
const point2 = { lat: 34.0000, lng: -118.2000 };
const dist = geohash.distance(point1, point2);
console.log(`Distance between (${point1.lat}, ${point1.lng}) and (${point2.lat}, ${point2.lng}): ${dist.toFixed(2)} miles`);

view raw JSON →