couchdbpoint-of-interest

query CouchDB to get poi within a certain radius


I want to create a CouchDB database with some POI's. Is there a way/query to get poi's within a certain radius (lets say 50 meters) from a given lat/long position?

I saw an extension https://github.com/couchbase/geocouch , but this means I have to recompile CouchDB, but at this moment I don't have admin access to do that.


Solution

  • I have an alternative proposal for your use case. The proposal is to use geohashes.

    You can store the position in the document as a geohash. The lenght of the geohash will depends on the precission you would like to store.

    Let consider that you stored the position with around 150 meters precession. In this case, you'll have a geohash of 7 characters like 'gbsukp7'. Check this for testing.

    Then your map function can be redefined in this way:

    function (doc) {
     emit([doc.geohash.substr(0,4), /* 39.1km × 19.5km bounding box */
          doc.geohash.substr(0,5), /* 4.89km ×  4.89km bounding box */
          doc.geohash.substr(0,6), /* 1.22km ×  0.61km bounding box */
          doc.geohash /* 153m × 153m bounding box */
          ],null)
    }
    

    With this approach you can have a simple mechanism to get the documents located in the same bounding box than the point of refrence.

    It is not perfect but could be an option