Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

geotrie

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geotrie

Store and search geo data. Geohashes and stores latitude/longitude coordinates and provides a search interface.


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

#Geotrie Store and search geo data. Geohashes and stores latitude/longitude coordinates and provides a search interface.

Right now depends on leveldb, as it uses the lexographical sorting of leveldb to provide a trie like data structure and efficient search algorithm. However this approach can and should be generalized to work in memory and with other databases.

Heavily borrowed from / inspired by level-trie and level-places. Thanks to Julian Gruber.

##Usage

var level = require('level')
var GeoTrie = require('geotrie')
var geotrie = geotrie(level(__dirname + '/db'))

geotrie.add({lat: 1, lon: 1}, 'SomeReferenceString')
geotrie.add({lat: 1.01, lon: 1}, 'OtherReferenceString')

geotrie.search({lat: 1, lon: 1}).toArray(function(err, results){
  //...
})

Results will come in the form of

{
  distance: 10, //in meters
  pos: {lat: 1, lon 1}, //stored position (will not be exact because of geohashing fidelity loss)
  ref: 'your string' //the reference string supplied during .add
}

Search Options ###hardLimit (Int) If supplied the search will immediately return after reaching this number of results (setting hard limit may result in omitted results that are closer to the centroid than other returned results) ###softLimit (Int) Usually a better option to setting hardLimit - If hit, the search will finish streaming after it completes it's current resolution level ###maxResolution (int) Defaults to 12. The search will start from the max resolution. If your relevant results will always be far apart then you can set this number lower for small efficiency gains ###minResolution (int) Defaults to 0. The search will end at this resolution even if the hard/soft limits have not been met.

##Notes Unfortunately geohash's are roughly rectangular in shape (and generally not square). If using a 2^(odd) base odd precision hash boxes will be square - all other hash boxes are about twice as big in the longitudinal direction at the equator (it reverses as you travel to extreme latitudes where longitudinal distances pinch).

##Geohash Precision Assuming base16 geohashing (4 bits per character) the hash precision will be as follows:

PrecisionLat ErrorLon Error
21248.75 km2497.5 km
478.046875 km156.09375 km
64.8779296875 km9.755859375 km
8304.870605469 m609.741210938 m
1019.0544128418 m38.1088256836 m
121.19090080261 m2.38180160522 m

FAQs

Package last updated on 20 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc