作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个 map 功能
function (doc) {
// Leidse plein
// this is now fixed, but needs to be dynamic from the url params
center_latitude = 52.3648111;
center_longitude = 4.8810906;
// this is fixed, but also needs to be dynamic from the url params
radius = 5;
// calc distance between centerpoint and userpoint
distance = Math.acos(
Math.sin(doc.latitude * Math.PI / 180) *
Math.sin(center_latitude * Math.PI / 180)
+
Math.cos(doc.latitude * Math.PI / 180) *
Math.cos(center_latitude * Math.PI / 180) *
Math.cos((doc.longitude - center_longitude) * Math.PI / 180)) * 6371;
// all poi's within 5km radius
if(distance <= radius ) {
emit([doc.title,doc.latitude,doc.longitude], distance);
}
}
所以这行得通,但我需要让它动态化,以便我可以从 url 参数传递 center_longitude 和 center_latitude。我还是 CouchDB 的新手。有人可以帮我解决这个问题吗?
最佳答案
map 函数中不能有参数。
我给你指了一个 similar question但它不适用于您的情况。
list functions或 filter functions可以接收 url 参数,但是如果数据库中的文档数量随着需要处理的完整数据库而增长,您将遇到一些性能问题。
关于javascript - 如何将 url 参数传递给 couchdb 映射函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729773/
我是一名优秀的程序员,十分优秀!