首页
/ Node-Geohash 技术文档

Node-Geohash 技术文档

2024-12-24 11:51:29作者:田桥桑Industrious

1. 安装指南

安装方式

Node-Geohash 是一个用于 Node.js 的 Geohash 库。你可以通过 npm 来安装这个库。

npm install ngeohash

2. 项目使用说明

基本用法

安装完成后,你可以在你的 Node.js 项目中引入 ngeohash 模块,并使用其提供的功能。

var geohash = require('ngeohash');

// 编码经纬度为 Geohash 字符串
console.log(geohash.encode(37.8324, 112.5584));
// 输出: ww8p1r4t8

// 解码 Geohash 字符串为经纬度
var latlon = geohash.decode('ww8p1r4t8');
console.log(latlon.latitude);  // 输出: 37.8324
console.log(latlon.longitude); // 输出: 112.5584

基本方法

geohash.encode(latitude, longitude, precision=9)

将一对经纬度值编码为 Geohash 字符串。第三个参数是可选的,用于指定 Geohash 字符串的长度,从而影响其精度。

geohash.decode(hashstring)

将 Geohash 字符串解码为经纬度值。返回一个包含 latitudelongitude 键的 JavaScript 对象。

geohash.decode_bbox(hashstring)

将 Geohash 字符串解码为匹配的边界框。返回一个四元素数组:[minlat, minlon, maxlat, maxlon]

geohash.bboxes(minlat, minlon, maxlat, maxlon, precision=9)

获取 [minlat, minlon][maxlat, maxlon] 之间的所有 Geohash 字符串。这些字符串可以用于在缓存中查找 POI。

geohash.neighbor(hashstring, direction)

在指定方向上查找 Geohash 字符串的邻居。方向是一个二维数组,例如 [1,0] 表示北,[-1,-1] 表示西南。

geohash.neighbors(hashstring)

查找 Geohash 字符串的所有 8 个邻居 [n, ne, e, se, s, sw, w, nw]

整数方法

geohash.encode_int(latitude, longitude, bitDepth=52)

将一对经纬度值编码为 Geohash 整数。第三个参数是可选的,用于指定整数的 bitDepth,从而影响其精度。

geohash.decode_int(hashinteger, bitDepth=52)

将 Geohash 整数解码为经纬度值。返回一个包含 latitudelongitude 键的 JavaScript 对象。

geohash.decode_bbox_int(hashinteger, bitDepth=52)

将 Geohash 整数解码为匹配的边界框。返回一个四元素数组:[minlat, minlon, maxlat, maxlon]

geohash.bboxes_int(minlat, minlon, maxlat, maxlon, bitDepth=52)

获取 [minlat, minlon][maxlat, maxlon] 之间的所有 Geohash 整数。

geohash.neighbor_int(hashinteger, direction, bitDepth=52)

在指定方向上查找 Geohash 整数的邻居。

geohash.neighbors_int(hashinteger, bitDepth=52)

查找 Geohash 整数的所有 8 个邻居 [n, ne, e, se, s, sw, w, nw]

3. 项目 API 使用文档

编码与解码

  • geohash.encode(latitude, longitude, precision=9):将经纬度编码为 Geohash 字符串。
  • geohash.decode(hashstring):将 Geohash 字符串解码为经纬度。

边界框

  • geohash.decode_bbox(hashstring):解码 Geohash 字符串为边界框。
  • geohash.bboxes(minlat, minlon, maxlat, maxlon, precision=9):获取指定范围内的所有 Geohash 字符串。

邻居

  • geohash.neighbor(hashstring, direction):查找指定方向的邻居。
  • geohash.neighbors(hashstring):查找所有 8 个邻居。

整数编码与解码

  • geohash.encode_int(latitude, longitude, bitDepth=52):将经纬度编码为 Geohash 整数。
  • geohash.decode_int(hashinteger, bitDepth=52):将 Geohash 整数解码为经纬度。

整数边界框

  • geohash.decode_bbox_int(hashinteger, bitDepth=52):解码 Geohash 整数为边界框。
  • geohash.bboxes_int(minlat, minlon, maxlat, maxlon, bitDepth=52):获取指定范围内的所有 Geohash 整数。

整数邻居

  • geohash.neighbor_int(hashinteger, direction, bitDepth=52):查找指定方向的邻居。
  • geohash.neighbors_int(hashinteger, bitDepth=52):查找所有 8 个邻居。

4. 项目安装方式

Node-Geohash 可以通过 npm 进行安装:

npm install ngeohash

安装完成后,你可以在项目中通过 require('ngeohash') 引入并使用该库。

登录后查看全文
热门项目推荐

热门内容推荐

最新内容推荐

项目优选

收起
kernelkernel
deepin linux kernel
C
22
6
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
132
1.89 K
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
8
0
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
193
273
金融AI编程实战金融AI编程实战
为非计算机科班出身 (例如财经类高校金融学院) 同学量身定制,新手友好,让学生以亲身实践开源开发的方式,学会使用计算机自动化自己的科研/创新工作。案例以量化投资为主线,涉及 Bash、Python、SQL、BI、AI 等全技术栈,培养面向未来的数智化人才 (如数据工程师、数据分析师、数据科学家、数据决策者、量化投资人)。
Jupyter Notebook
70
63
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
379
389
Cangjie-ExamplesCangjie-Examples
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
Cangjie
344
1.24 K
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
915
548
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
144
189
ShopXO开源商城ShopXO开源商城
🔥🔥🔥ShopXO企业级免费开源商城系统,可视化DIY拖拽装修、包含PC、H5、多端小程序(微信+支付宝+百度+头条&抖音+QQ+快手)、APP、多仓库、多商户、多门店、IM客服、进销存,遵循MIT开源协议发布、基于ThinkPHP8框架研发
JavaScript
96
15