Giter Club home page Giter Club logo

node-geohash's Introduction

node-geohash

Geohash library for nodejs.

Build Status NPM version Dependencies

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

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 hook in npm install. ngeohash.js will be generated during npm install, 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 (rlib) for geohash.

Contributors

License

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

node-geohash's People

Contributors

alsotang avatar arjunmehta avatar four43 avatar sunng87 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.