public function index() { if (Input::get('coordinates')) { $cd = Input::get('coordinates'); $_cd = explode(',', $cd); $wd = $_cd[0]; $jd = $_cd[1]; $schools = School::all(); $ret = array(); $radius = Input::get('radius') ? Input::get('radius') : 30000; foreach ($schools as $v) { $tmp = explode(',', $v->coordinates); $lat1 = $tmp[0]; $lng1 = $tmp[1]; $dst = $this->getDistance($lat1, $lng1, $wd, $jd); if ($dst < $radius) { $ret[floor($dst)] = $v; } ksort($ret); $out = []; foreach ($ret as $v) { $out[] = $v; } } return $this->output(array('schoolList' => $out)); } else { return $this->output(array('schoolList' => School::orderBy('ord', 'desc')->limit(4)->get())); } }