擅长:python、mysql、java
<p>如果你的坐标不排序,你的搜索只能在假设是<code>(latitude,longitude)</code>的情况下稍加改进,先在纬度上过滤地球</p>
<blockquote>
<p>1 degree of latitude on the sphere is 111.2 km or 69 miles</p>
</blockquote>
<p>但这不会给你带来巨大的加速。</p>
<p>如果首先按纬度对机场进行排序,则可以使用二进制搜索来查找第一个<em>可以</em>匹配的机场(<code>airport_lat >= point_lat-tolerance</code>),然后只与最后一个<em>可以</em>匹配的机场(<code>airport_lat <= point_lat+tolerance</code>)进行比较,但要注意0度等于360度。虽然不能直接使用该库,<a href="https://docs.python.org/3/library/bisect.html" rel="nofollow">bisect</a>的源代码是实现二进制搜索的良好开端。</p>
<p>从技术上讲,这种搜索方式仍然是O(n),但实际距离计算(取决于公差)要少得多,纬度比较也很少。所以你会有一个巨大的加速。</p>