Experimental - subject to change.
$ npm install level-geospatial
The module takes a leveldb database (or a sub-level):
var db = 'path_to_your_database';var geo = db;
You can then start adding key/values, along with latitude/longitude values.
// lat, lon, key, valuegeo;
You can retrieve a value back like this:
// this is the fast way of getting the valuegeo;// this is the slower/convenient way of getting the valuegeo;// the data returned looks like this:quadKey: '1222222212112112222210'position:lat: 52081959lon: 1415904id: 'Location1'value: 'My value'
You can search within a radius (in meters) of a given point:
// lat, lon, radius in metersgeo;// the data returned looks like this:quadKey: '1222222212112112222210'position:lat: 52081959lon: 1415904id: 'Location1'value: 'My value'distance: 1232232323 // this is the distance in meters from your search
Please note, the results are not returned in any meaningful order.
You can update/delete like this:
// to update the value/location:geo;// to deletegeo;
The data is indexed using a quadtree. When you index a point, it's quadkey is calculated to a depth of 22.
The quadkey is a string which stores where the point lives in the quadtree. The quadkey notation used is the same as Bing Maps. The quadkeys can be inserted into this URL to retrieve a map tile for a given location:
When you search the database, the quadkey is calculated for search location. The radius is then used to calculate an appropriate depth in the quadtree to search to.
Potential matches within those quads are then tested using a simple distance calculation to work out if they are close enough to be included in the results.
Currently searches that span the international date line will not return all results. Batch operations are not supported.