我正在使用MIT App Inventor开发应用程序。从应用程序,我发送当前位置纬度和经度到PHP。我有一个mysql表存储完整的地址,包括lat和long。这是查询。
$sSQL= "SELECT *,(((acos(sin((".$lat1."*pi()/180)) * sin((latitude*pi()/180))+cos((".$lat1."*pi()/180)) * cos((latitude*pi()/180)) * cos(((".$long1."- longitude)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance_var FROM DIVE_LOC HAVING distance_loc < 5 ORDER BY distance LIMIT 0 , 20";
我在php中使用以下代码来比较距离..
$theta = $longitudeFrom - $longitudeTo;
$dist = sin(deg2rad($latitudeFrom)) * sin(deg2rad($latitudeTo)) + cos(deg2rad($latitudeFrom)) * cos(deg2rad($latitudeTo)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$distance = ($miles * 1.609344);
比较结果,这是输出
PHP value - 0.32493112554566 # mySQL value -0.320931017946721
PHP value - 0.49010759578908 # mySQL value -0.49327293708344117
PHP value - 0.49010759578908 # mySQL value -0.49327293708344117
PHP value - 0.65728970497002 # mySQL value -0.6598218485814622
PHP value - 0.88521338025908 # mySQL value -0.8844764825185991
PHP value - 1.1443186694143 # mySQL value -1.1438416915550529.
我只是想知道值是否存在某些差异。两者都不能完全相同。