douheng8629 2017-02-22 06:18 采纳率: 100%
浏览 7

相同的PHP文件在XAMPP中工作但在我的实时网站中没有

Previously I used this code & query to find location within some miles of radius, But it seems like it does not give proper result.

$zip = $r['zip'];
$lat1 = number_format((float)$r['latitude'],8,'.','');
$lon1 = number_format((float)$r['longitude'],8,'.','');
$d = $miles;
$r = 3959;
//compute max and min latitudes / longitudes for search square
 $latN = number_format((float)rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(0)))),7,'.','');
 $latS =  number_format((float)rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(180)))),7,'.','');
 $lonE =  number_format((float)rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(90)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN)))),7,'.','');
 $lonW =  number_format((float)rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(270)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN)))),7,'.','');

 $rs = "SELECT * FROM loc WHERE (latitude <= $latN AND latitude >= $latS AND longitude <= $lonE AND longitude >= $lonW) OR zip= '$szip' OR city = '$scity'  OR state = '$scity'";

Now I changed this code to below code:

$zip = $r['zip'];
$lat1 = number_format((float)$r['latitude'],8,'.','');
$lon1 = number_format((float)$r['longitude'],8,'.','');
$d = $miles;

 $rs = "SELECT zip, latitude, longitude,( 3959 * acos( cos( radians(".$lat1.") ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(".$lon1.") ) + sin( radians(".$lat1.") ) * sin( radians( latitude ) ) ) ) AS distance FROM stores HAVING distance < $distance ORDER BY distance";

But it works only in local, in my live website it gives blank result. what is issue? & can any one suggest me good way to find location within some miles of radius?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录