-3

hi I have a Branches with a Position table

in my Branches Model class I have:

public function position()
{
    return $this->hasOne('Model\Branch\Position');
}

in the Position table I have:

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

public function branches()
{
    return $this->belongsTo('Model\Branch','branch_id');
}

now I get the latitude and longitude of my client

how I can show him what branches he have in here 20 KM radios?

the simple why with Eloquent

OMR
  • 11,736
  • 5
  • 20
  • 35
haisom
  • 125
  • 1
  • 1
  • 9
  • https://stackoverflow.com/questions/1006654/fastest-way-to-find-distance-between-two-lat-long-points – Rwd Sep 06 '17 at 15:46
  • To ask an On Topic questions, please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [What topics to avoid](https://stackoverflow.com/help/dont-ask) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) **We are very willing to help you fix your code, but we dont write code for you** – RiggsFolly Sep 06 '17 at 15:46

1 Answers1

0

Am using below code for similar task.It is working for me:

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

Please refer to the below link for detail:

http://www.geodatasource.com/developers/php

OMR
  • 11,736
  • 5
  • 20
  • 35
SNG
  • 358
  • 4
  • 15