【发布时间】:2018-04-30 12:55:06
【问题描述】:
我想交叉比较包含位置数据(纬度、经度)的多个对象之间的距离。目标是从一堆位置计算最远的两个位置。我已经知道如何计算两个位置之间的距离,但是如果您有多个位置怎么办?
function FarthestDistance(points) {
// here this function should cross compare all objects within 'points' to calculate which two locations have the furthest distance between them
// the function should calculate the distance between each point in a recursive manner and return the two farthest points back
}
var obj = {{lat1,lon1},{lat2,lon2},{lat3,lon3},{lat4,lon4}};
FarthestDistance(obj);
希望现在很清楚。谢谢。
【问题讨论】:
-
您好,看来您需要帮助。您能否提供输入和预期输出示例。此外,展示您迄今为止所做的尝试也很有帮助。
-
感谢您的评论,我已经添加了更多解释。
-
首先,将其设为`var obj = [{....}]。然后:一个循环。跟踪 obj1 和 obj2 之间的距离。然后obj1和obj3之间的距离。然后在 obj1 和 obj4 之间。接下来,跟踪 obj2 和 obj3 之间的距离等。通过跟踪我的意思是哪个距离最大。
标签: javascript arrays object