gpt4 book ai didi

javascript - 如何将 url 参数传递给 couchdb 映射函数

转载 作者:行者123 更新时间:2023-11-30 20:36:55 25 4
gpt4 key购买 nike

我有这个 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 functionsfilter functions可以接收 url 参数,但是如果数据库中的文档数量随着需要处理的完整数据库而增长,您将遇到一些性能问题。

关于javascript - 如何将 url 参数传递给 couchdb 映射函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com