我有一张叫做地方的桌子:
id | name | coordinates (longitude, latitude)
1 | London | -0.12574, 51.50853
2 | Manchester | -2.25, 53.41667
3 | Glasgow | -4.25, 55.86667
坐标列是点数据类型.我使用以下方法将点插入到位置表中:
st_geomfromtext('point($longitude $latitude)', 4326)
请注意,我已经使用了SRID.
给定任何坐标,我想找到最近的位置(按升序排序).我目前提出的解决方案(通过阅读MySQL文档)看起来像这样:
select
*,
st_distance_sphere(`place`.`coordinates`, st_geomfromtext('Point($longitude $latitude)', 4326)) as distance
from place
order by distance asc;
在这里和其他地方看到无数类似的问题之后,很明显这是一个鲜为人知的(和更新的方式)做事情所以没有太多的内容,所以我为什么要寻求一些澄清.
我的问题是:
>这是最好的解决方案/我这样做了吗?
>这个方法会利用我在坐标列上的空间索引吗?
>使用st_distance_sphere时,是否需要指定地球的半径才能获得准确的结果? (编辑:不,它默认使用地球的半径)
编辑,这是这些答案:
解释选择…;收益:
id | se