Laravel 8 Find Nearest Location By Latitude and Longitude

Laravel 8 Find Nearest Location By Latitude and Longitude

Hello friends, Today we will show how to find nearest location using latitude and longitude in laravel. In this example we will provide latitude and longitude in laravel, get address from latitude and longitude laravel, laravel distance between coordinates.

Laravel 8 Find Near by Location using Latitude and Longitude

$latitude = "23.033863";
     $longitude = "72.585022";

     $users = User::select("name", \DB::raw("6371 * acos(cos(radians(" . $latitude . "))
             * cos(radians(latitude)) * cos(radians(longitude) - radians(" . $longitude . "))
             + sin(radians(" .$latitude. ")) * sin(radians(latitude))) AS distance"))
             ->having('distance', '<', 1000)
             ->orderBy('distance')
             ->get()->toArray();

I hope you understand of laravel find near by location and it can help you…

Read Also :  Laravel Resize Image Before Upload