douluan5444 2017-01-13 16:24
浏览 44

PHP PDO选择当前位置半径的位置

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");
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探