In this tutorial, we will learn How to find the nearest location using latitude and longitude in laravel
Example:
$lat = YOUR_CURRENT_LATTITUDE;
$lon = YOUR_CURRENT_LONGITUDE;
DB::table("posts")
->select("posts.id"
,DB::raw("6371 * acos(cos(radians(" . $lat . "))
* cos(radians(posts.lat))
* cos(radians(posts.lon) - radians(" . $lon . "))
+ sin(radians(" .$lat. "))
* sin(radians(posts.lat))) AS distance"))
->groupBy("posts.id")
->get();
May this example help you.