onlinecode

Find Nearest Location By Latitude and Longitude in Laravel 6 – onlinecode

Find Nearest Location By Latitude and Longitude in Laravel 6 – onlinecode

In this post we will give you information about Find Nearest Location By Latitude and Longitude in Laravel 6 – onlinecode. Hear we will give you detail about Find Nearest Location By Latitude and Longitude in Laravel 6 – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this article, we can display the Nearest Location using the google map of Latitude and Longitude in laravel 6.

If you want to display a specific place according to a nearby place then you can display the Nearest Location using the below following example.

SQL Query

6371 * acos(cos(radians(" . $lat . ")) 

        * cos(radians(orders.latitude)) 

        * cos(radians(orders.longitude) - radians(" . $lon . ")) 

        + sin(radians(" .$lat. ")) 

        * sin(radians(orders.latitude))) AS distance

 

Example

$lat = YOUR_CURRENT_LATTITUDE;
$lon = YOUR_CURRENT_LONGITUDE;
   
DB::table("orders")
    ->select("orders.id"
        ,DB::raw("6371 * acos(cos(radians(" . $lat . ")) 
        * cos(radians(orders.latitude)) 
        * cos(radians(orders.longitude) - radians(" . $lon . ")) 
        + sin(radians(" .$lat. ")) 
        * sin(radians(orders.latitude))) AS distance"))
        ->groupBy("orders.id")
        ->get();

Please follow and like us:

Hope this code and post will helped you for implement Find Nearest Location By Latitude and Longitude in Laravel 6 – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github