Php 拉雷维尔经纬度最近的城市

Php 拉雷维尔经纬度最近的城市,php,sql,laravel,geolocation,Php,Sql,Laravel,Geolocation,如何在PHP-Laravel中从纬度和经度查找最近的城市(用户位置[lat,long]) 表结构: 地点:'lon,lat' $loc = explode(',', $request->get('location')); $results = Agent::select(Agent::raw('SELECT id, ( 3959 * acos( cos( radians(' . $loc[0] . ') ) * cos( radians( lat ) ) * cos( radians(

如何在PHP-Laravel中从纬度和经度查找最近的城市(用户位置[lat,long])

表结构: 地点:'lon,lat'

$loc = explode(',', $request->get('location'));

$results = Agent::select(Agent::raw('SELECT id, ( 3959 * acos( cos( radians(' . $loc[0] . ') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(' . $loc[1] . ') ) + sin( radians(' . $loc[0] .') ) * sin( radians(lat) ) ) ) AS distance FROM articles HAVING distance < ' . 200 . ' ORDER BY distance') )->get();
$agents =  \App\Agent::
where('name','like','%'.$request->get('text').'%')
->orWhere('manager','like','%'.$request->get('text').'%')
->orWhere('address','like','%'.$request->get('text').'%')
->orWhere('phone','like','%'.$request->get('text').'%')->get();
foreach ($agents as $agent) {
    $agent->location = explode(',', $agent->location);
}
return $agents;
用户位置:“lon,lat”

$loc = explode(',', $request->get('location'));

$results = Agent::select(Agent::raw('SELECT id, ( 3959 * acos( cos( radians(' . $loc[0] . ') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(' . $loc[1] . ') ) + sin( radians(' . $loc[0] .') ) * sin( radians(lat) ) ) ) AS distance FROM articles HAVING distance < ' . 200 . ' ORDER BY distance') )->get();
$agents =  \App\Agent::
where('name','like','%'.$request->get('text').'%')
->orWhere('manager','like','%'.$request->get('text').'%')
->orWhere('address','like','%'.$request->get('text').'%')
->orWhere('phone','like','%'.$request->get('text').'%')->get();
foreach ($agents as $agent) {
    $agent->location = explode(',', $agent->location);
}
return $agents;
$loc=explode(',',$request->get('location');
$results=Agent::select(Agent::raw('select id,(3959*acos(弧度('.$loc[0]))*cos(弧度(lat))*cos(弧度(lng)-弧度('.$loc[1]))+sin(弧度('.$loc[0])*sin作为与距离小于0.200的物品的距离)->get();
$agents=\App\Agent::
其中('name'、'like'、'%'。$request->get('text').%。)
->或其中('manager'、'like'、'%'。$request->get('text').%。)
->orWhere('address'、'like'、'%'。$request->get('text').%)
->或者where('phone'、'like'、'%'。$request->get('text').'%')->get();
foreach($代理作为$代理){
$agent->location=分解(“,”,$agent->location);
}
返回$2代理;

Search@dilekkoçI不使用谷歌地图。阅读这篇文章,了解如何在lat附近和long@dilekkoçPlz看到表结构了吗?到目前为止,您尝试了什么?应该有很多关于这个主题的教程