1.0.1 • Published 7 months ago

node-geohash v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

geohash

This package is based on latlon-geohash by Chris Veness adapted and refactored for TypeScript applications. Original code is under MIT License.

Functions to convert a geohash to/from a latitude/longitude point, and to determine bounds of a geohash cell and find neighbours of a geohash.

API

  • Geohash.encode(lat, lon, [precision]): encode latitude/longitude point to geohash of given precision (number of characters in resulting geohash); if precision is not specified, it is inferred from precision of latitude/longitude values.
  • Geohash.decode(geohash): return { lat, lon } of centre of given geohash, to appropriate precision.
  • Geohash.bounds(geohash): return { sw, ne } bounds of given geohash.
  • Geohash.adjacent(geohash, direction): return adjacent cell to given geohash in specified direction (N/S/E/W).
  • Geohash.neighbours(geohash): return all 8 adjacent cells (n/ne/e/se/s/sw/w/nw) to given geohash.

Note to obtain neighbours as an array, you can use

const neighboursObj = Geohash.neighbours(geohash);
const neighboursArr = Object.keys(neighboursObj).map(n => neighboursObj[n]);

The parent of a geocode is simply geocode.slice(0, -1).

If you want the geohash converted from Base32 to Base4, you can e.g.:

parseInt(Geohash.encode(52.20, 0.12, 6), 32).toString(4);

Usage

Geohash can be used in a Node.js app from npm:

$ npm install node-geohash 
> import Geohash from 'node-geohash';
> const geohash = Geohash.encode(52.20, 0.12, 6);
> console.assert(geohash == 'u120fw');
> const latlon = Geohash.decode('u120fw');
> console.assert(JSON.stringify(latlon) == '{"lat":52.1988,"lon":0.115}');
acornacorn-jsxacorn-walkajvansi-colorsansi-escapesansi-regexansi-stylesanymatchargargparsearray-buffer-byte-lengtharray-includesarray-unionarray.prototype.findlastindexarray.prototype.flatarray.prototype.flatmaparray.prototype.reducearraybuffer.prototype.sliceassertion-errorasyncasyncroautoprefixeravailable-typed-arraysbabel-jestbabel-plugin-istanbulbabel-plugin-jest-hoistbabel-plugin-macrosbabel-plugin-polyfill-corejs2babel-plugin-polyfill-corejs3babel-plugin-polyfill-regeneratorbabel-plugin-transform-async-to-promisesbabel-plugin-transform-replace-expressionsbabel-preset-current-node-syntaxbabel-preset-jestbalanced-matchboolbasebrace-expansionbracesbrotli-sizebrowser-stdoutbrowserslistbs-loggerbserbuffer-frombuiltin-modulesbuiltinscall-bindcallsitescamelcasecaniuse-apicaniuse-litechalkchar-regexcheck-errorci-infocjs-module-lexercliuicocollect-v8-coveragecolor-convertcolor-namecolordcommandercommondirconcat-mapconcat-with-sourcemapsconvert-source-mapcore-js-compatcosmiconfigcreate-jestcreate-requirecross-spawncss-declaration-sortercss-selectcss-treecss-whatcssesccssnanocssnano-preset-defaultcssnano-utilscssodata-view-bufferdata-view-byte-lengthdata-view-byte-offsetdebugdecamelizededentdeep-eqldeep-isdeepmergedefine-data-propertydefine-lazy-propdefine-propertiesdetect-newlinediffdiff-sequencesdir-globdoctrinedom-serializerdomelementtypedomhandlerdomutilsduplexerejselectron-to-chromiumemitteryemoji-regexentitieserror-exes-abstractes-array-method-boxes-properlyes-define-propertyes-errorses-object-atomses-set-tostringtages-shim-unscopableses-to-primitiveescaladeescape-string-regexpeslint-compat-utilseslint-import-resolver-nodeeslint-module-utilseslint-plugin-es-xeslint-scopeeslint-visitor-keysespreeesprimaesqueryesrecurseestraverseestree-walkeresutilseventemitter3execaexitexpectfast-deep-equalfast-difffast-globfast-json-stable-stringifyfast-levenshteinfastqfb-watchmanfiguresfile-entry-cachefilelistfilesizefill-rangefind-cache-dirfind-upflatflat-cacheflattedfor-eachfraction.jsfs-extrafs.realpathfseventsfunction-bindfunction.prototype.namefunctions-have-namesgeneric-namesgensyncget-caller-fileget-func-nameget-intrinsicget-package-typeget-streamget-symbol-descriptionget-tsconfigglobglob-parentglobalsglobalthisglobalyzerglobbyglobrexgopdgraceful-fsgraphemergrowlgzip-sizehas-ansihas-bigintshas-flaghas-property-descriptorshas-protohas-symbolshas-tostringtaghasownhehtml-escaperhuman-signalsicss-replace-symbolsicss-utilsignoreimport-cwdimport-freshimport-fromimport-localimurmurhashinflightinheritsinternal-slotis-array-bufferis-arrayishis-bigintis-boolean-objectis-bufferis-builtin-moduleis-callableis-core-moduleis-data-viewis-date-objectis-dockeris-extglobis-fullwidth-code-pointis-generator-fnis-globis-moduleis-negative-zerois-numberis-number-objectis-path-insideis-referenceis-regexis-shared-array-bufferis-streamis-stringis-symbolis-typed-arrayis-weakrefis-wslisarrayisexeistanbul-lib-coverageistanbul-lib-instrumentistanbul-lib-reportistanbul-lib-source-mapsistanbul-reportsjakejest-changed-filesjest-circusjest-clijest-configjest-diffjest-docblockjest-eachjest-environment-nodejest-get-typejest-haste-mapjest-leak-detectorjest-matcher-utilsjest-message-utiljest-mockjest-pnp-resolverjest-regex-utiljest-resolvejest-resolve-dependenciesjest-runnerjest-runtimejest-snapshotjest-utiljest-validatejest-watcherjest-workerjs-tokensjs-yamljsescjson-bufferjson-parse-even-better-errorsjson-schema-traversejson-stable-stringify-without-jsonifyjson5jsonfilekeyvkleurlevenlevnlilconfiglines-and-columnsloader-utilslocate-pathlodashlodash.camelcaselodash.debouncelodash.memoizelodash.mergelodash.uniqlog-symbolsloupelru-cachemagic-stringmake-dirmake-errormakeerrormaxminmdn-datamerge-streammerge2micromatchmimic-fnminimatchminimistmkdirpmrimsnanoidnatural-comparenode-environment-flagsnode-int64node-releasesnormalize-pathnormalize-rangenormalize-urlnpm-run-pathnth-checknumber-is-nanobject-assignobject-inspectobject-keysobject.assignobject.fromentriesobject.getownpropertydescriptorsobject.groupbyobject.valuesonceonetimeopenoptionatorp-finallyp-limitp-locatep-queuep-timeoutp-tryparent-moduleparse-jsonpath-existspath-is-absolutepath-keypath-parsepath-typepathvalpicocolorspicomatchpifypiratespkg-dirpossible-typed-array-namespostcsspostcss-calcpostcss-colorminpostcss-convert-valuespostcss-discard-commentspostcss-discard-duplicatespostcss-discard-emptypostcss-discard-overriddenpostcss-load-configpostcss-merge-longhandpostcss-merge-rulespostcss-minify-font-valuespostcss-minify-gradientspostcss-minify-paramspostcss-minify-selectorspostcss-modulespostcss-modules-extract-importspostcss-modules-local-by-defaultpostcss-modules-scopepostcss-modules-valuespostcss-normalize-charsetpostcss-normalize-display-valuespostcss-normalize-positionspostcss-normalize-repeat-stylepostcss-normalize-stringpostcss-normalize-timing-functionspostcss-normalize-unicodepostcss-normalize-urlpostcss-normalize-whitespacepostcss-ordered-valuespostcss-reduce-initialpostcss-reduce-transformspostcss-selector-parserpostcss-svgopostcss-unique-selectorspostcss-value-parserprelude-lsprettier-linter-helperspretty-bytespretty-formatpromise.seriespromptspunycodepure-randqueue-microtaskrandombytesreact-isregenerateregenerate-unicode-propertiesregenerator-runtimeregenerator-transformregexp.prototype.flagsregexpu-coreregjsgenregjsparserrequire-directoryrequire-main-filenameresolveresolve-cwdresolve-fromresolve-pkg-mapsresolve.exportsreusifyrimrafrolluprollup-plugin-bundle-sizerollup-plugin-postcssrollup-plugin-terserrollup-plugin-typescript2rollup-plugin-visualizerrollup-pluginutilsrun-parallelsadesafe-array-concatsafe-buffersafe-identifiersafe-regex-testsemverserialize-javascriptset-blockingset-function-lengthset-function-nameshebang-commandshebang-regexside-channelsignal-exitsisteransislashsource-mapsource-map-jssource-map-supportsourcemap-codecsprintf-jsstablestack-utilsstring-hashstring-lengthstring-widthstring.prototype.matchallstring.prototype.trimstring.prototype.trimendstring.prototype.trimstartstrip-ansistrip-bomstrip-final-newlinestrip-json-commentsstyle-injectstylehackssupports-colorsupports-preserve-symlinks-flagsvgosynckittersertest-excludetext-tabletiny-globtmplto-regex-rangets-api-utilstsconfig-pathstslibtype-checktype-detecttype-festtyped-array-buffertyped-array-byte-lengthtyped-array-byte-offsettyped-array-lengthunbox-primitiveundici-typesunicode-canonical-property-names-ecmascriptunicode-match-property-ecmascriptunicode-match-property-value-ecmascriptunicode-property-aliases-ecmascriptuniversalifyupdate-browserslist-dburi-jsutil-deprecatev8-compile-cache-libv8-to-istanbulwalkerwhichwhich-boxed-primitivewhich-modulewhich-typed-arraywide-alignword-wrapwrap-ansiwrappywrite-file-atomicy18nyallistyamlyargsyargs-parseryargs-unparserynyocto-queue
1.0.1

7 months ago

1.0.0

7 months ago