2

我想用一些 POI 创建一个 CouchDB 数据库。有没有办法/查询从给定的纬度/经度位置获取一定半径(比如说 50 米)内的 poi?

我看到了一个扩展https://github.com/couchbase/geocouch,但这意味着我必须重新编译 CouchDB,但此时我没有管理员权限来执行此操作。

4

2 回答 2

0

解决了它并做了一个地图功能:

function (doc) {

// Leidse plein
latitude = 52.3648111;
longitude = 4.8810906;

distance = Math.acos(
  Math.sin(doc.latitude * Math.PI / 180) * 
  Math.sin(latitude * Math.PI / 180) 
  + 
  Math.cos(doc.latitude * Math.PI / 180) * 
  Math.cos(latitude * Math.PI / 180) * 
  Math.cos((doc.longitude - longitude) * Math.PI / 180)) * 6371;

  // all poi's within 5km radius
  if(distance <= 5 ) {
      emit([doc.title,doc.latitude,doc.longitude], distance);
  }

 }
于 2018-04-08T20:38:58.613 回答
0

对于您的用例,我有一个替代建议。建议是使用geohashes

您可以将文档中的位置存储为 geohash。geohash 的长度将取决于您想要存储的精度。

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

于 2018-04-09T20:48:46.577 回答