How to get latitude longitude from mysql in Laravel?

Today now in this post i will show you how to get latitude longitude from mysql in laravel. Whenever we need to get the nearest posts from the lat and long and if we are working on laravel query builder. Then we can get the distance easily by using DB::raw(), so here you can learn from the following example how to get nearest value from mysql in laravel application.

$lat = 1;
$lon = 1;
		,DB::raw("6371 * acos(cos(radians(" . $lat . ")) 
		* cos(radians( 
		* cos(radians(posts.lon) - radians(" . $lon . ")) 
		+ sin(radians(" .$lat. ")) 
		* sin(radians( AS distance"))

Read Also :Laravel Join with Subquery in Query Builder Example

Thanks for read. I hope it help you. For more you can follow us on facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →