How to get latitude longitude from mysql in Laravel?

By Hardik Savani | March 9, 2016 | Category : Laravel MySql

Whenever you need to get nearest posts from lat and long and if you are working on laravel query builder. then you can get distance easily using DB::raw(), so you can learn from following example how to get nearest value from mysql laravel.


$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"))



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.