Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lloricode/25c962582fe76acb9b21b87c0ce387d1 to your computer and use it in GitHub Desktop.

Select an option

Save lloricode/25c962582fe76acb9b21b87c0ce387d1 to your computer and use it in GitHub Desktop.

Revisions

  1. @stephan-v stephan-v created this gist Dec 1, 2015.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    private function findNearestLocation(Request $request)
    {
    $location = DB::table('locations')
    ->select('name', 'latitude', 'longitude', 'region', DB::raw(sprintf(
    '(6371 * acos(cos(radians(%1$.7f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%2$.7f)) + sin(radians(%1$.7f)) * sin(radians(latitude)))) AS distance',
    $request->input('latitude'),
    $request->input('longitude')
    )))
    ->having('distance', '<', 50)
    ->orderBy('distance', 'asc')
    ->get();

    return $location;
    }