Skip to content

store and retrieve data in leveldb using a lat/long pair in a given radius

License

Notifications You must be signed in to change notification settings

gerhardberger/level-nearby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

level-nearby

store data with a given lat/long pair and retrieve all the entries given a lat/long pair and a radius in that radius. the module uses google's s2 library in node.

example

var level  = require('level');
var nearby = require('level-nearby');

var db = nearby(level('./db'));

db.put({ lat: 34.0908829, lng: -118.3856206 }, 'foo', function (err) {
  if (err) console.log(err);
  console.log('success');
});

db.createNearStream({ lat: 34.0908829, lng: -118.3646206, radius: 2000 })
  .on('data', function (data) {
  console.log(data.value);      // prints 'foo'
});

methods

var nearby = require('level-nearby');

nearby(db, options)

transforms db the be able to perform the put and createNearStream methods on it. options can have a prefix field, than the methods will have that prefix.

db.put(keyObj, value[, options][, callback]))

insert value in db with a key that represents the given latitude (lat) and longitude (lng) in keyObj. keyObj can have a customKey than that makes the key unique. By default the customKey is a timestamp. If keyObj is a String it falls back to the default put function. callback's second argument after the error is the key String which it was saved with.

db.createNearStream(searchObj)

retrieves the entries in db that are in the radius of the lat, lng pair. returns a read stream with the results. radius is measured in meters. In the retrieved data object there is a _nearby field besides key and value, containing a lat, lng, distance field.

install

npm install level-nearby

license

MIT

About

store and retrieve data in leveldb using a lat/long pair in a given radius

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published