Order by nearest - PostGIS, GeoRuby, spatial_adapter

后端 未结 6 2203
醉酒成梦
醉酒成梦 2021-02-06 04:03

I\'m trying to do an order query that finds records nearest to the current_user.

I know the distance between the two points is: current_location.euclidean_distance

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 04:46

    If you really want to find literally the 5 records nearest to the current_user, consider neighborhood search, which is supported by KNN index in PostGIS 2.0 (see '<->' operator):

    SELECT * FROM your_table ORDER BY your_table.geom <-> ST_Geomfromtext(your point as wkt, 1000) LIMIT 5

提交回复
热议问题