Coder Social home page Coder Social logo

latlon-geohash's Introduction

geohash

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.

Methods summary:

  • encode: latitude/longitude point to geohash
  • decode: geohash to latitude/longitude
  • bounds of a geohash cell
  • adjacent neighbours of a geohash

Install

in browser

Download the JavaScript source and reference in HTML page using:

<script src="js/latlon-geohash.js"></script>

from npm

npm install --save latlon-geohash

Usage

  • 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

var neighboursObj = Geohash.neighbours(geohash);
var neighboursArr = Object.keys(neighboursObj).map(function(n) { return neighboursObj[n]; });

Note that the parent of a geocode is simply geocode.slice(0, -1).

Import within node.js

var Geohash = require('latlon-geohash');

Further details

More information (with interactive conversion) at www.movable-type.co.uk/scripts/geohash.html.

Full JsDoc at www.movable-type.co.uk/scripts/js/latlon-geohash/docs/Geohash.html.

latlon-geohash's People

Contributors

chrisveness avatar pbihler 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.