什么是计算最近点的有效方法? [英] What's an efficient way of calculating the nearest point?

查看:133
本文介绍了什么是计算最近点的有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有位置数据存储在Core Data对象,我想要能够获取和显示只是最近的点到当前位置。我知道有公式,将计算从当前的纬度/长度到存储的纬度/长度的距离,但我很好奇,执行这一点的一组1000+点存储在核心数据的最佳方式。我知道我可以将点从Core Data返回一个数组,然后循环遍历,寻找点之间的距离的最小值,但我想象一个更有效的方法,可能在某种程度上利用核心数据。 p>

任何洞察力都会受到赞赏。



编辑:
我不知道我错过了我的初始搜索,但此SO问题建议只是遍历Core数据对象的数组,但基于当前位置用边界框限制数组大小。这是我能做的最好的吗?

解决方案

从我可以收集,看起来好像最好的方法是使用当前位置周围的边界框返回点数组。



您可以检索当前位置的某个范围内的点,如果返回的数组为空,然后增加框的大小。一旦某些结果返回,计算数组中最近的并使用该点。


I have objects with location data stored in Core Data, I would like to be able to fetch and display just the nearest point to the current location. I'm aware there are formulas which will calculate the distance from current lat/long to a stored lat/long, but I'm curious about the best way to perform this for a set of 1000+ points stored in Core Data. I know I could just return the points from Core Data to an array and then loop through that looking for the min value for distance between the points but I'd imagine there's a more efficient method, possibly leveraging Core Data in some way.

Any insight would be appreciated.

EDIT: I don't know how I missed this on my initial search but this SO question suggests just iterating through an array of Core Data objects but limiting the array size with a bounding box based on the current location. Is this the best I can do?

解决方案

From what I can gather, it looks as though the best approach in this case is to return an array of points using a bounding box around the current location.

You can retrieve points within a certain range of the current location, if the returned array is empty, then increase the size of the box. Once some results come back, calculate the nearest in the array and use that point.

这篇关于什么是计算最近点的有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆