//附近帖子列表
public function nearbyPost()
{
$latitude = input("latitude");
$longitude = input("longitude");
$list = P::withJoin(['userInfo' => ['username', 'avatar'], 'topicInfo'])
->fieldRaw("ST_Distance_Sphere(point(".$longitude.", ".$latitude."),point(post.longitude,post.latitude))/1000 as distance")
->order('distance asc')
->paginate(10)->each(function ($item) use ($latitude, $longitude) {
return $item;
});
return success($list);
}
ThinkPHP6 坐标距离排序,使用SQL函数ST_Distance_Sphere
最新推荐文章于 2024-08-29 04:18:26 发布