本文介绍了distanceFromLocation方法如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常对 CLLocation 对象使用 distanceFromLocation 方法来获取它们与其他位置的距离。枚举一个CLLocations数组,然后使用此方法将每个位置与参考位置进行比较。

I frequently use the distanceFromLocation method for CLLocation objects to get their distance from other locations. Enumerating through an array of CLLocations, I then compare each to my reference location using this method.

我很好奇知道使用<$ c的处理/内存含义$ c> distanceFromLocation ,尤其是对于连续的大量 CLLocation 对象。此方法如何起作用-它是否连接到服务器以获取数据,还是根据某些数学公式(例如?

I'm curious to know the processing/memory implications for using distanceFromLocation, especially for a large number of CLLocation objects in succession. How does this method work - does it connect to the server to get the data, or does it calculate the distance based on some mathematical formula, such as the Haversine Formula?

有没有一种更有效的方法来比较1个参考位置和一组CLLocation对象之间的距离?

Is there a more efficient method to compare distances between 1 reference location and an array of CLLocation objects?

推荐答案

他们可能正在使用余弦的球法而不是Haversine()。

They are likely are using the Spherical Law of Cosines instead of the Haversine (why? see this question).

如果您要做的只是将许多点与一个点进行比较,以找出最接近的点,那么您可能就不在乎计算距离的准确性了,关于性能。在这种情况下,也许可以使用毕达哥拉斯的定理为您工作。

If all you want to do is compare many points against one point to see which is closest, then maybe you don't care about the accuracy of the computed distance and just about performance. In that case perhaps using Pythagoras' theorem would work for you.

所有这些算法均在,其中部分内容为:

All of these algorithms are detailed on this web page, which says in part:

If performance is an issue and accuracy less important, for small
distances Pythagoras’ theorem can be used on an equirectangular
projection:*

您可以使用毕达哥拉斯(Pythagoras)定理实现一个函数,然后将其与CLLocation中的函数进行基准比较,并与我的,该函数使用余弦的球法则来了解性能之间的差异。

You could implement a function using Pythagoras' theorem then benchmark it against the one in CLLocation and against my implementation of distanceInMetersFromRadians that uses the Spherical Law of Cosines to see how much performance difference there is.

这篇关于distanceFromLocation方法如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 12:08