Hello readers!, If you are having a project in PHP and need to calculate the distance from lat and longs you can use the code below:-
Here all the entries are saved in table('business')
(SELECT name, ACOS(SIN(RADIANS($latitude))*SIN(RADIANS(business.latitude))+COS(RADIANS($latitude))*
COS(RADIANS(business.latitude))*COS(RADIANS(business.longitude)-RADIANS($longitude))) * 3959 AS distance,'business'
FROM `business` having distance <=5000 ORDER BY distance ASC)";
This Mysql query will give you all the records of which the distance is less than 5000 KM from business table
0 Comment(s)