【问题标题】:query CouchDB to get poi within a certain radius查询 CouchDB 获取一定半径内的 poi
【发布时间】:2018-09-17 05:50:01
【问题描述】:

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

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

【问题讨论】:

  • 我认为您无法绕过对 Geocouch 的需求。也许如果你安装了 Docker,你可以使用 Geocouch 获取 Docker 镜像并以这种方式运行。
  • hmm .. 我以前在 PHP/Mysql 中使用过这个:stackoverflow.com/questions/37159089/php-radius-search 这可以翻译成 CouchDB 查询吗?

标签: couchdb point-of-interest


【解决方案1】:

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

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

假设您存储了大约 150 米进动的位置。在这种情况下,您将拥有一个包含 7 个字符的 geohash,例如“gbsukp7”。检查this 进行测试。

那么你的map函数可以这样重新定义:

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)
}

通过这种方法,您可以使用一种简单的机制来使文档位于与参考点相同的边界框中。

它并不完美,但可能是一种选择

【讨论】:

  • 嗯..但我不明白如何动态设置框。我的意思是,这就像一个可以在盒子里获取 poi 的应用程序,所以我每次都需要提供盒子数据。所以盒子不是硬编码的。
  • 哦等等..我刚刚意识到..我可以计算中心点geohash并将其发送到视图。然后在我的 couchDB 中,我已经有了计算地理哈希的文档,然后匹配它
  • 您不需要计算中心点,只需将参考位置编码为具有您需要的精度的 geohash。然后在视图过滤中使用它: ...?startkey=["gbsu"]&endkey=["gbsu",{}]
  • 是的..这就是我的意思:)
【解决方案2】:

解决了,做了个map函数:

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);
  }

 }

【讨论】:

  • 我很好奇,你要乘的6371 常数是多少?
  • 地球半径KM
  • latitude = 52.3648111;longitude = 4.8810906; 的值是否始终不变?您不需要更改它们吗?
  • 我还在想办法;)。当我有一个工作示例时会在这里发布
  • 是的,所以才发现,地图函数不接受自定义 GET uri 变量 :( 所以我无法设置中心点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 2013-08-30
  • 2014-11-02
相关资源
最近更新 更多