Laravel 拉维尔-哈弗森计算
我使用此工具计算两点之间的距离:Laravel 拉维尔-哈弗森计算,laravel,laravel-5,laravel-5.1,haversine,laravel-eloquent,Laravel,Laravel 5,Laravel 5.1,Haversine,Laravel Eloquent,我使用此工具计算两点之间的距离: $location = new CnpPoi(28.535153, -81.383219); $destination = new CnpPoi(42.594018, -88.433886) $location->getDistanceInMilesTo($destination); $location->getDistanceInMetersTo($destination); 需要在查询中使用它,以便按照距离已通过url his$lat e$lo
$location = new CnpPoi(28.535153, -81.383219);
$destination = new CnpPoi(42.594018, -88.433886)
$location->getDistanceInMilesTo($destination);
$location->getDistanceInMetersTo($destination);
需要在查询中使用它,以便按照距离已通过url his$lat e$long的给定点的距离对存储进行排序。
如何在查询中使用此函数?语法错误1064您的SQL语法有错误;检查与您的MariaDB服务器对应的手册-第3行(SQL:select
tb_users
*,(6371*acos(弧度(41.9242814))*cos(弧度(纬度))*cos(弧度(长)-弧度(12.4923974))+sin(弧度(41.9242814))*sin(弧度(纬度)))作为与tb_用户的距离order bydistance
desc)(视图:/home/gethelpme/public_html/local/resources/views/user/risultati.blade.php)(视图:/home/gethelpme/public_html/local/resources/views/user/risultati.blade.php)哦,很抱歉,这个答案是针对mysql的,而不是MariaDB。请在你的问题中贴上mariaDb标签
public function getStoresNear($latitude, $lngitude){
$stores = Store::select('stores.*')
->selectRaw('( 6371 * acos( cos( radians(?) ) *
cos( radians( store_lat ) )
* cos( radians( store_long ) - radians(?)
) + sin( radians(?) ) *
sin( radians( store_lat ) ) )
) AS distance', [$latitude, $longitude, $latitude])
->orderBy('distance', 'desc')
->get();
return $stores;
}