find distance from latitude and longitude with mysql
$radius = 1;
$my_lat = 21.21586;
$my_long = 72.86315;
//3959 for miles and 6371 for km
$res = mysql_query("SELECT *, ( 3959 * acos( cos( radians('$my_lat') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('$my_long') ) + sin( radians('$my_lat') ) * sin( radians( latitude ) ) ) ) AS distance FROM map_point HAVING distance < '$radius' ORDER BY distance");
returns data from 1 mile radius from given $my_lat and $my_long
$my_lat = 21.21586;
$my_long = 72.86315;
//3959 for miles and 6371 for km
$res = mysql_query("SELECT *, ( 3959 * acos( cos( radians('$my_lat') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('$my_long') ) + sin( radians('$my_lat') ) * sin( radians( latitude ) ) ) ) AS distance FROM map_point HAVING distance < '$radius' ORDER BY distance");
returns data from 1 mile radius from given $my_lat and $my_long
No comments:
Post a Comment