Hey I have a MySQL table of stores that contains latitude and longitude in every row, When the user get in the android app he has an option to filter the stores in a radius he choose, I need to write a php code that will only select and print the stores inside the radius the user choose, for now I take an example of lower than 100, every code I searched doesn't seem to work for me, here is some of my php code:
a distance function I tried:
function distance($lat1, $lon1, $lat2, $lon2) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
return ($miles * 1.609344);
}
and here is the select statement:
$my_lat = $_POST["lat"];
$my_long = $_POST["lon"];
if($my_lat != null)
{
$stmt = $db->query("SELECT * FROM app HAVING distance(lat,lon,'$my_lat','$my_long')<100");
}