Php 使用position和MYSQL(纬度和经度)

Php 使用position和MYSQL(纬度和经度),php,laravel,eloquent,position,Php,Laravel,Eloquent,Position,嗨,我有一个带位置表的分支 在我的分支模型类中,我有: public function position() { return $this->hasOne('Model\Branch\Position'); } 在职位表中,我有: protected $fillable = ['latitude','longitude','branch_id','business_id']; public function branches() { return $this->b

嗨,我有一个带位置表的分支

在我的分支模型类中,我有:

public function position()
{
    return $this->hasOne('Model\Branch\Position');
}
在职位表中,我有:

protected $fillable = ['latitude','longitude','branch_id','business_id'];

public function branches()
{
    return $this->belongsTo('Model\Branch','branch_id');
}
现在我得到了我客户的经纬度

我怎样才能让他知道他在这里有什么分支20公里的无线电


“简单的为什么”和“雄辩的”

我使用下面的代码来完成类似的任务。它对我很有用:

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
      return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
  } else {
      return $miles;
  }
}
有关详细信息,请参阅以下链接:


若要提出主题问题,请阅读并了解如何创建我们非常愿意帮助您修复代码,但我们不会为您编写代码