使用 mysql 数据库。我有一列“latlong”,它是一个带有空间索引的点类型。我想获得距离经纬度最近 4 英里的最近位置。
到目前为止,我有这个...
SELECT `postcode`,county, ( 3959 * acos( cos( radians(51.585738) ) * cos( radians( x(GeomFromText(astext(latlong))) ) ) * cos( radians( y(GeomFromText(astext(latlong))) ) - radians(-0.260878) ) + sin( radians(51.585738) ) * sin( radians( x(GeomFromText(astext(latlong))) ) ) ) ) AS distance
FROM uk_p HAVING distance < 4 ORDER BY distance LIMIT 0 , 20
我只有 2900 条记录,大约需要 0.0277 秒。无论如何优化这个查询,因为我担心随着数据库的增长,这个查询会越慢......