@geonet/geohash

中文文档
1.0.16发布于 2020/10/29MITESM + CJS零依赖近 30 天下载 3019

Geohash decode/encoder

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. encode
  4. decode
  5. neighbors
  6. GeohashStream
  7. GeohashStreamGeoJSON

@geonet/geohash

NPM

coverage report

Geohash decode/encoder

PrecisionWidthHeight
1≤ 5,000km× 5,000km
2≤ 1,250km× 625km
3≤ 156km× 156km
4≤ 39.1km× 19.5km
5≤ 4.89km× 4.89km
6≤ 1.22km× 0.61km
7≤ 153m× 153m
8≤ 38.2m× 19.1m
9≤ 4.77m× 4.77m
10≤ 1.19m× 0.596m
11≤ 149mm× 149mm
12≤ 37.2mm× 18.6mm

Installation

npm i @geonet/geohash

Deployment
npm run lint
npm run test
rm -rf docs/ && npm run docs
npm run build
np

Usage

Basic usage:

const Geohash = require( '@geonet/geohash' );
const hash = Geohash.encode( -77.480, 38.866, 7 ); // hash: 'dqbvhgk'

encode

Encodes longitude/latitude to geohash, either to specified precision or to automatically evaluated precision.

params

  • lng {number} Longitude in degrees.
  • lat {number} Latitude in degrees.
  • precision {number} Number of characters in resulting geohash.

returns: Geohash of supplied longitude/latitude.

const hash = Geohash.encode( -77.480, 38.866, 7 ); // hash: 'dqbvhgk'

decode

Decode geohash to longitude/latitude (location is approximate center of geohash cell, to reasonable precision).

params

  • geohash {string} Geohash string to be converted to longitude/latitude.

returns: (Center of) geohashed location.

const latlng = Geohash.decode( 'dqbvhgk' ); // latlng: { lng: -77.4804, lat: 38.8662 }

neighbors

Returns 8 adjacent cells to specified geohash.

params

  • geohash {string} Geohash to find neighbors of.
  • asObject {boolean} return geohashes in an object ({c,n,ne,e,se,s,sw,w,nw})

returns: surrounding geohashes

const latlng = Geohash.neighbors( 'dqcjpxetzh6q' );
[
    'dqcjpxetzh6r', 'dqcjpxetzh6x', 'dqcjpxetzh6w', 'dqcjpxetzh6t',
    'dqcjpxetzh6m', 'dqcjpxetzh6j', 'dqcjpxetzh6n', 'dqcjpxetzh6p'
]

Example:

Geohash.neighbors( 'dqcjpxetzh6q' );

           ┬────────────────────────────────────────────────────┐
           │      'west'          'center'         'east'       │
┼──────────┼────────────────────────────────────────────────────┤
│ 'north'  │   'dqcjpxetzh6p'  'dqcjpxetzh6r'  'dqcjpxetzh6x'   │
│ 'center' │   'dqcjpxetzh6n'  'dqcjpxetzh6q'  'dqcjpxetzh6w'   │
│ 'south'  │   'dqcjpxetzh6j'  'dqcjpxetzh6m'  'dqcjpxetzh6t'   │
┴──────────┴────────────────────────────────────────────────────┘

GeohashStream

GeohashStream takes in a BBox and streams geohashes within that bbox.

params

  • minLng {number} bbox min longitude
  • minLat {number} bbox min latitude
  • maxLng {number} bbox max longitude
  • maxLat {number} bbox max latitude
  • precision {number=7} geohash precision (defaults to 7)
new Geohash.GeohashStream( 0.1, 52.2, 0.2, 52.3, 3 )
    .on( 'data', d => console.log( d.toString() ) )
    .on( 'end', () => console.log( 'done' ) );

// u12

GeohashStreamGeoJSON

GeohashStreamGeoJSON is the same as GeohashStream but streams back GeoJSON

params

  • minLng {number} bbox min longitude
  • minLat {number} bbox min latitude
  • maxLng {number} bbox max longitude
  • maxLat {number} bbox max latitude
  • precision {number=7} geohash precision (defaults to 7)
new Geohash.GeohashStreamGeoJSON( 0.1, 52.2, 0.2, 52.3, 3 )
    .on( 'data', d => console.log( d.toString() ) )
    .on( 'end', () => console.log( 'done' ) );

// {
// 	"type": "Feature",
// 	"bbox": [ 0, 52.03125, 1.40625, 53.4375 ],
// 	"properties": {},
// 	"geometry": {
// 		"type": "Polygon",
// 		"coordinates": [ [
// 			[ 0, 52.03125 ],
// 			[ 1.40625, 52.03125 ],
// 			[ 1.40625, 53.4375 ],
// 			[ 0, 53.4375 ],
// 			[ 0, 52.03125 ]
// 		] ]
// 	}
// }

版本与发布记录

@geonet/geohash 共发布 10 个版本,首次发布于 2019/02/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.16latest2020/10/296 年前
1.0.152020/10/286 年前
1.0.142020/06/296 年前
1.0.132019/11/196 年前
1.0.122019/11/067 年前
1.0.112019/11/067 年前

关于 @geonet/geohash 的常见问题

@geonet/geohash 是什么?

Geohash decode/encoder

如何安装 @geonet/geohash?

在项目目录运行 npm install @geonet/geohash,或使用 pnpm add / yarn add / bun add。

@geonet/geohash 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/geonet__geohash 是否存在。

@geonet/geohash 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@geonet/geohash 可以商用吗?

@geonet/geohash 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@geonet/geohash 的下载量有多少?

根据 npm 官方下载统计,@geonet/geohash 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,019 次,日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@geonet/geohash 还在维护吗?

最新版本 1.0.16 发布于 2020/10/29(6 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。