• Stars
    star
    565
  • Rank 78,889 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

geohash library for nodejs

node-geohash

Geohash library for nodejs.

Build Status NPM version Dependencies Donate

Install

npm install ngeohash

Usage

var geohash = require('ngeohash');
console.log(geohash.encode(37.8324, 112.5584));
// prints ww8p1r4t8
var latlon = geohash.decode('ww8p1r4t8');
console.log(latlon.latitude);
console.log(latlon.longitude);

Basic Methods

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

Encode a pair of latitude and longitude values into a geohash. The third argument is optional, you can specify a length of this hash string, which also affects the precision of the geohash.

geohash.decode (hashstring)

Decode a hash string into pair of latitude and longitude values. A javascript object is returned with latitude and longitude keys.

geohash.decode_bbox (hashstring)

Decode hashstring into a bounding box that matches it. Data is returned as a four-element array: [minlat, minlon, maxlat, maxlon].

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

Get all hashstringes between [minlat, minlon] and [maxlat, maxlon]. These keys can be used to find a poi stored in the cache with hashstring keys. eg. show all points in the visible range of map. [minlat, minlon] correspond to the southwest starting hash, whereas [maxlat, maxlon] correspond to the northeast starting hash.

geohash.neighbor (hashstring, direction)

Find the neighbor of a geohash string in certain direction. Direction is a two-element array, i.e. [1,0] means north, [-1,-1] means southwest.

geohash.neighbors (hashstring)

Find all 8 geohash neighbors [n, ne, e, se, s, sw, w, nw] of a geohash string. This method is more efficient than running the geohash.neighbor method multiple times for all directions. array: [hashstr1, hashstr2, ... ]

Integer Methods

Note that integer precision is capped at 52bits in Javscript. These are just regular javascript floating point numbers, but the functionality should mimic other uint64 geohash functions in geohash libraries for other languages and are compatible with the geohash integers produced by them, however any geohash integer encoded in anything more than 52bits will be resolved to 52bits resolution.

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

Encode a pair of latitude and longitude values into a geohash integer. The third argument is optional, you can specify the bitDepth of this number, which affects the precision of the geohash but also must be used consistently when decoding. Bit depth must be even.

geohash.decode_int (hashinteger, bitDepth=52)

Decode a integer geohashed number into pair of latitude and longitude value approximations. A javascript object is returned with latitude and longitude keys. You should also provide the bitDepth at which to decode the number (ie. what bitDepth the number was originally produced with), but will default to 52.

geohash.decode_bbox_int (hashinteger, bitDepth=52)

Decode an integer geohash into the bounding box that matches it. Data is returned as a four-element array: [minlat, minlon, maxlat, maxlon].

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

Get all geohash integers between [minlat, minlon] and [maxlat, maxlon]. These keys can be used to find a poi stored in the cache with geohash integer keys. eg. show all points in the visible range of map

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

Find the neighbor of a geohash integer in certain direction. Direction is a two-element array, i.e. [1,0] means north, [-1,-1] means southwest. The bitDepth should be specified, but defaults to 52 bits.

geohash.neighbors_int (hashinteger, bitDepth=52)

Find all 8 neighbors [n, ne, e, se, s, sw, w, nw] of a geohash integer. This method is more efficient than running the geohash.neighbor method multiple times for all directions. The bitDepth should be specified, but defaults to 52 bits.

Node-Geohash for browser

We recently added a browserify script with npm run browserify. ngeohash.js will be generated and you can use this file in your javascript application for browser.

<script src="./path/to/ngeohash.js"></script>
<script>
alert(ngeohash.encode(114.23, 38.23));
</script>

About Geohash

Check Wikipedia for more information.

See Also

Geohash.rs: node-geohash ported to Rust: A rust library for geohash.

License

node-geohash is open sourced under MIT License, of course.

Donation

I'm now accepting donation on liberapay, if you find my work helpful and want to keep it going.

More Repositories

1

handlebars-rust

Rust templating with Handlebars
Rust
1,089
star
2

heatcanvas

Pixel based heatmap with html5 canvas.
JavaScript
401
star
3

slacker

Transparent, non-incursive RPC by clojure and for clojure
Clojure
356
star
4

diehard

Clojure resilience library for flexible retry, circuit breaker and rate limiter
Clojure
309
star
5

ring-jetty9-adapter

An enhanced version of jetty adapter for ring, with additional features like websockets, http/2 and http/3
Clojure
228
star
6

pgwire

PostgreSQL wire protocol implemented as a rust library.
Rust
163
star
7

shake

clojure library that shakes your shell
Java
122
star
8

handlebars-iron

Handlebars middleware for Iron web framework
Rust
118
star
9

slacker-cluster

Clojure Micro-Service framework based on Slacker RPC
Clojure
77
star
10

pyclj

talking clojure with python - an edn implementation for python
Python
63
star
11

lein-jlink

A lein plugin creates and manages custom java environment
Clojure
59
star
12

hbs

clojure templating by handlebars.java
Clojure
48
star
13

papaline

Clojure concurrent pipleline on core.async
Clojure
47
star
14

rigui

Hierarchical Timing Wheels for Clojure and ClojureScript
Clojure
45
star
15

urdict

command line urban dictionary
Rust
42
star
16

stavka

Stavka manages configuration from various sources, for your Clojure application.
Clojure
41
star
17

exaile-doubanfm-plugin

An alternative choice to enjoy personalized music from douban.fm
Python
40
star
18

openbirdingmap

eBird location and observation data rendered on OpenStreetMap
Clojure
35
star
19

metriki

Rust metrics ported from dropwizard metrics
Rust
27
star
20

reddit.clj

A clojure wrapper for Reddit API
Clojure
25
star
21

rustmann

A riemann client on tokio, async/await
Rust
20
star
22

clojalk

A beanstalkd (distributed task queue) clone in clojure
Clojure
20
star
23

Exaile-Soundmenu-Indicator

integrate exaile with sound menu indicator
Python
19
star
24

cljts

A clojure wrapper of JTS, implements Simple Feature Specification of OGC
Clojure
17
star
25

clojuredocs-android

An Android app for ClojureDocs
JavaScript
14
star
26

lein-control

A lein plugin for clojure control
Clojure
12
star
27

tojson_macros

Simple rust syntax extension generates default ToJson implementation
Rust
11
star
28

timing

clojure syntax sugars for perf4j
Clojure
11
star
29

iron-json-response

Json response middleware for iron
Rust
10
star
30

stages

SEDA framework
Java
7
star
31

exaile-doubanfm-gnome-shell-extension

Exaile DoubanFM Control on GNOME-shell
JavaScript
7
star
32

bason

annotaion driven bson mapping tookit
Java
6
star
33

rageviewer

A rage comic viewer in clojure
Clojure
6
star
34

slacker-rust

Slacker RPC implemented by Rust and for Rust
Rust
4
star
35

greptimedb-bin.aur

AUR repository for GreptimeDB
Shell
4
star
36

lein-bootclasspath-deps

A Leiningen plugin to manage your bootclasspath.
Clojure
4
star
37

slacker-python

python client for slacker
Python
3
star
38

lazypress

Simplified online writing and publishing
JavaScript
3
star
39

sway-im.aur

Sway with input method popup support, packaged as AUR
Shell
2
star
40

mapzei

A maps extension for Ruman Nurik's live wallpaper app Muzei.
Java
2
star
41

karmalet

working in progress
Clojure
2
star
42

debug

Clojure port of nodejs debug
Clojure
2
star
43

link-socketio

Socketio server with link API
Clojure
2
star
44

slacker-htrace

Distributed tracing support for Slacker RPC using Apache HTrace
Clojure
2
star
45

nordenize

A project aimed to transform any webpage into nord color theme.
TypeScript
2
star
46

Artificial301

a simple firefox plugin and google appengine help you to get real link behind feedburner/feedproxy.google.com and url shorten services
JavaScript
2
star
47

alpine-jlink-base

Minimal base image for custom JRE created from jlink
1
star
48

handlebars-gotham

Handlebars templating middleware for Gotham
Rust
1
star
49

slacker-metrics

The metrics middleware for slacker RPC
Clojure
1
star
50

athtool

Command line TOTP generator
Rust
1
star
51

radar

redis proxy [WIP]
Clojure
1
star
52

metaq

A set of metaq API in favour of clojure
Clojure
1
star
53

leancloud-rtm-blacklist

LeanCloud 实时通信聊天室黑名单范例
JavaScript
1
star
54

datafusion-postgres

Rust
1
star
55

greptimedb-metabase-driver

A metabase driver plugin for GreptimeDB
Clojure
1
star