Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 拉维尔-哈弗森计算_Laravel_Laravel 5_Laravel 5.1_Haversine_Laravel Eloquent - Fatal编程技术网

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 by
distance
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;
}